/**
* Interoperability metadata.
* 互操作性元数据。
* This can be extended by other proposals.
* 这可以通过其他提案进行扩展。
*
* All fields MUST be optional.
* 所有字段都必须是可选的。
* **Not every field has to be a boolean.** Any optional JSON-serializable object can be used by extensions.
* **并非每个字段都必须是布尔值。** 任何可选的 JSON 可序列化对象都可以被扩展使用。
*/interfaceInteroperabilityMetadata{/**
* This MUST be true if this is ERC-1046 Token Metadata, otherwise, this MUST be omitted.
* 如果这是 ERC-1046 代币元数据,则必须为 true,否则必须省略。
* Setting this to true indicates to wallets that the address should be treated as an ERC-20 token.
* 将其设置为 true 表示钱包应将该地址视为 ERC-20 代币。
**/erc1046?:boolean|undefined;/**
* This MUST be true if this is ERC-721 Token Metadata, otherwise, this MUST be omitted.
* 如果这是 ERC-721 代币元数据,则必须为 true,否则必须省略。
* Setting this to true indicates to wallets that the address should be treated as an ERC-721 token.
* 将其设置为 true 表示钱包应将该地址视为 ERC-721 代币。
**/erc721?:boolean|undefined;/**
* This MUST be true if this is ERC-1155 Token Metadata, otherwise, this MUST be omitted.
* 如果这是 ERC-1155 代币元数据,则必须为 true,否则必须省略。
* Setting this to true indicates to wallets that the address should be treated as an ERC-1155 token.
* 将其设置为 true 表示钱包应将该地址视为 ERC-1155 代币。
**/erc1155?:boolean|undefined;}
ERC-20 扩展
ERC-20 接口扩展
符合标准的合约必须实现以下 Solidity 接口:
pragmasolidity^0.8.0;/// @title ERC-20 Metadata Extension
/// @title ERC-20 元数据扩展
interfaceERC20TokenMetadata/* is ERC20 */{/// @notice Gets an ERC-721-like token URI
/// @notice 获取类似 ERC-721 的代币 URI
/// @dev The resolved data MUST be in JSON format and support ERC-1046's ERC-20 Token Metadata Schema
/// @dev 已解析的数据必须为 JSON 格式,并支持 ERC-1046 的 ERC-20 代币元数据架构
functiontokenURI()externalviewreturns(string);}
/**
* Asset Metadata
* 资产元数据
*/interfaceERC20TokenMetadata{/**
* Interoperability, to differentiate between different types of tokens and their corresponding URIs.
* 互操作性,用于区分不同类型的代币及其对应的 URI。
**/interop:InteroperabilityMetadata;/**
* The name of the ERC-20 token.
* ERC-20 代币的名称。
* If the `name()` function is present in the ERC-20 token and returns a nonempty string, these MUST be the same value.
* 如果 `name()` 函数存在于 ERC-20 代币中并返回一个非空字符串,则这些必须是相同的值。
*/name?:string;/**
* The symbol of the ERC-20 token.
* ERC-20 代币的符号。
* If the `symbol()` function is present in the ERC-20 token and returns a nonempty string, these MUST be the same value.
* 如果 `symbol()` 函数存在于 ERC-20 代币中并返回一个非空字符串,则这些必须是相同的值。
*/symbol?:string;/**
* The decimals of the ERC-20 token.
* ERC-20 代币的小数位数。
* If the `decimals()` function is present in the ERC-20 token, these MUST be the same value.
* 如果 `decimals()` 函数存在于 ERC-20 代币中,则这些必须是相同的值。
* Defaults to 18 if neither this parameter nor the ERC-20 `decimals()` function are present.
* 如果此参数和 ERC-20 `decimals()` 函数都不存在,则默认为 18。
*/decimals?:number;/**
* Provides a short one-paragraph description of the ERC-20 token, without any markup or newlines.
* 提供对 ERC-20 代币的简短一段描述,没有任何标记或换行符。
*/description?:string;/**
* A URI pointing to a resource with mime type `image/*` that represents this token.
* 指向具有 mime 类型 `image/*` 的资源的 URI,表示此代币。
* If the image is a bitmap, it SHOULD have a width between 320 and 1080 pixels
* 如果图像是位图,则其宽度应在 320 到 1080 像素之间
* The image SHOULD have an aspect ratio between 1.91:1 and 4:5 inclusive.
* 图像的纵横比应在 1.91:1 到 4:5 之间(包括两者)。
*/image?:string;/**
* One or more URIs each pointing to a resource with mime type `image/*` that represents this token.
* 一个或多个 URI,每个 URI 都指向具有 mime 类型 `image/*` 的资源,表示此代币。
* If an image is a bitmap, it SHOULD have a width between 320 and 1080 pixels
* 如果图像是位图,则其宽度应在 320 到 1080 像素之间
* Images SHOULD have an aspect ratio between 1.91:1 and 4:5 inclusive.
* 图像的纵横比应在 1.91:1 到 4:5 之间(包括两者)。
*/images?:string[];/**
* One or more URIs each pointing to a resource with mime type `image/*` that represent an icon for this token.
* 一个或多个 URI,每个 URI 都指向具有 mime 类型 `image/*` 的资源,表示此代币的图标。
* If an image is a bitmap, it SHOULD have a width between 320 and 1080 pixels, and MUST have a height equal to its width
* 如果图像是位图,则其宽度应在 320 到 1080 像素之间,并且高度必须等于其宽度
* Images MUST have an aspect ratio of 1:1, and use a transparent background
* 图像的纵横比必须为 1:1,并使用透明背景
*/icons?:string[];}
ERC-721 扩展
对 ERC-721 元数据架构的扩展
实现 ERC-721 并使用其代币元数据 URI 的合约应使用以下 TypeScript 扩展来扩展元数据 URI:
interfaceERC721TokenMetadataInteropextendsERC721TokenMetadata{/**
* Interoperability, to avoid confusion between different token URIs
* 互操作性,以避免不同代币 URI 之间的混淆
**/interop:InteroperabilityMetadata;}
pragmasolidity^0.8.0;/// @title ERC-1155 Metadata URI Interoperability Extension
/// @title ERC-1155 元数据 URI 互操作性扩展
interfaceERC1155TokenMetadataInterop/* is ERC1155 */{/// @notice Gets an ERC-1046-compliant ERC-1155 token URI
/// @notice 获取一个符合 ERC-1046 的 ERC-1155 代币 URI
/// @param tokenId The token ID to get the URI of
/// @param tokenId 要获取 URI 的代币 ID
/// @dev The resolved data MUST be in JSON format and support ERC-1046's Extension to the ERC-1155 Token Metadata Schema
/// @dev 解析的数据必须为 JSON 格式,并支持 ERC-1046 的 ERC-1155 代币元数据架构的扩展
/// This MUST be the same URI as the `uri(tokenId)` function, if present.
/// 如果存在,这必须与 `uri(tokenId)` 函数的 URI 相同。
functiontokenURI(uint256tokenId)externalviewreturns(string);}
对 ERC-1155 元数据架构的扩展
实现 ERC-1155 并使用其代币元数据 URI 的合约建议使用以下扩展来扩展元数据 URI。实现 ERC-1155 接口扩展部分中描述的接口的合约必须使用以下 TypeScript 扩展:
interfaceERC1155TokenMetadataInteropextendsERC1155TokenMetadata{/**
* Interoperability, to avoid confusion between different token URIs
* 互操作性,以避免不同代币 URI 之间的混淆
**/interop:InteroperabilityMetadata;}
Tommy Nicholas (@tomasienrbc), Matt Russo (@mateosu), John Zettler (@JohnZettler), Matt Condon (@shrugs), Gavin John (@Pandapip1), "ERC-1046: tokenURI 互操作性," Ethereum Improvement Proposals, no. 1046, April 2018. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-1046.