跳转到内容

按名称获取代币元数据

GetTokensDataByName 会根据指定集合中代币的名称检索其元数据 URI。该查询特别适合市场展示集合内代币的元数据。

  • $token_nameString — 要在集合中搜索的代币名称。例如:"The Mexican"
  • $collectionIdString — 根据集合名称和创建者地址计算的集合 ID。例如:"0xe6a7399d10406b993e25d8a3bf24842413ba8f1a08444dbfa5f1c31b09f0d16e"

要获取集合 ID,可以使用以下 Python 代码片段:

import hashlib
def standardized_address(creator_address: str) -> str:
# Strip the '0x' prefix if it exists and format the address to be 64 characters long
handle = creator_address.removeprefix("0x") if creator_address.startswith("0x") else creator_address
return f"0x${handle:0>64}"
def sha256_hex(creator_address: str, collection_name: str) -> str:
# Process the creator address
processed_address = standardized_address(creator_address)
# Combine processed creator address and collection name
combined_string = f"${creator_address}::${collection_name}"
# Compute SHA256 hash and return as a hexadecimal string
return standardized_address(hashlib.sha256(combined_string.encode()).hexdigest())
# Example usage
creator_address = "0xc0e3fbf8ae61056d66ce624d71ccf1888f879355cc4e364ef117249b5e3160a8"
collection_name = "Aptomingos"
# Collection Id is `0xe6a7399d10406b993e25d8a3bf24842413ba8f1a08444dbfa5f1c31b09f0d16e`
print(sha256_hex(creator_address, collection_name))