# NFT Metadata三种模式 **Published by:** [Y.T.](https://paragraph.com/@yeetsai/) **Published on:** 2022-05-05 **URL:** https://paragraph.com/@yeetsai/nft-metadata ## Content 当前NFT Metadata设计思路因为NFT合约本身只有一个ID,无法承载更多信息,因此ERC-721引入了Metadata的概念,以供每个NFT描述自身的属性,/// @title ERC-721 Non-Fungible Token Standard, optional metadata extension /// @dev See https://eips.ethereum.org/EIPS/eip-721 /// Note: the ERC-165 identifier for this interface is 0x5b5e139f. interface ERC721Metadata /* is ERC721 */ { /// @notice A descriptive name for a collection of NFTs in this contract function name() external view returns (string _name); /// @notice An abbreviated name for NFTs in this contract function symbol() external view returns (string _symbol); /// @notice A distinct Uniform Resource Identifier (URI) for a given asset. /// @dev Throws if `_tokenId` is not a valid NFT. URIs are defined in RFC /// 3986. The URI may point to a JSON file that conforms to the "ERC721 /// Metadata JSON Schema". function tokenURI(uint256 _tokenId) external view returns (string); } { "title": "Asset Metadata", "type": "object", "properties": { "name": { "type": "string", "description": "Identifies the asset to which this NFT represents" }, "description": { "type": "string", "description": "Describes the asset to which this NFT represents" }, "image": { "type": "string", "description": "A URI pointing to a resource with mime type image/* representing the asset to which this NFT represents. Consider making any images at a width between 320 and 1080 pixels and aspect ratio between 1.91:1 and 4:5 inclusive." } } } 由于NFT最早面向艺术品,ERC-721可选Metadata接口JSON Schema只指定了name、description、image三个属性。但对于游戏而言,这些属性远远不够,因此EIP-1155将name、description、image属性转移到了URI的json里面,而不规定URI接口返回的JSON Schema。pragma solidity ^0.5.9; /** Note: The ERC-165 identifier for this interface is 0x0e89341c. */ interface ERC1155Metadata_URI { /** @notice A distinct Uniform Resource Identifier (URI) for a given token. @dev URIs are defined in RFC 3986. The URI MUST point to a JSON file that conforms to the "ERC-1155 Metadata URI JSON Schema". @return URI string */ function uri(uint256 _id) external view returns (string memory); } 当前NFT Metadata的不足之处ERC-721和EIP-1155的Metadata实现可以放到中心化系统或者IPFS上,由开发者根据业务情况修改元数据的内容,这些都是链下数据。链下数据对于合约的可组合性有极大的影响,如果有合约想直接通过与NFT组合,那么当只能通过外部url而不是直接从合约获取相关信息时,这种组合就无法进行,而可组合性是区块链和DeFi最有价值的特性之一。对于Financial NFT而言,元数据更是其根本,元数据的内容直接决定了这些NFT的价值/价格。 ERC-721之类的可更改的元数据不具有权威性和可信度,与智能合约中的状态相关度也不够(ERC-721合约标准实现中就没有业务状态),因此现有的ERC-721元数据相关模式远远不能满足类似Financial NFT这样更高级的NFT的数据描述。 uniswap V3 流动性LP NFT的tokenURI接口已不再返回url,而直接返回json,已经往前一步了。但返回的json仅包括流动性区间已经对应的svg图片代码, 对于流动性价值、比例等不能随之变化,所以只能算是一点改进。 最近的Loot,对元数据已经进行了正本清源的使用,虽然Loot使用图像来描述属性,但属性仅仅是一些文字,这样有了更好的组合性。Loot在可组合性上做的还不够,因为图片仅适合人阅读而不是适合机器。Financial NFT 元数据的设计思路基于NFT Metadata的现状和问题,Financial NFT需要更进一步,将合约的业务状态的元数据返回成自描述的结构化数据(JSON格式),而不能仅仅是一个图片,这样才能有更好的可组合性。 EIP-3525贴近Financial NFT的真实应用场景,进一步扩展ERC-721 tokenURI接口的内涵,更好的满足DeFi的可组合性,将金融票据的元数据/业务数据通过tokenURI返回人类可读的json字符串,这样就符合诸如OpenSea这些NFT市场的需要,可以方便的显示票据属性,但OpenSea这些市场还需要进一步进化以适应Financial NFT的需求,在浏览时实时访问合约以获取最新状态。 除此之外,EIP-3525才对NFT元数据的外延做了扩展,增加了诸如contractURI(), slotURI()这些不同的元数据接口,从各个维度对Financial NFT进行描述,dApp和其它合约可以方便的实时获取Financial NFT的各种业务状态。 具体EIP-3525元数据接口的详情,我们将在下一篇文章介绍。 ## Publication Information - [Y.T.](https://paragraph.com/@yeetsai/): Publication homepage - [All Posts](https://paragraph.com/@yeetsai/): More posts from this publication - [RSS Feed](https://api.paragraph.com/blogs/rss/@yeetsai): Subscribe to updates - [Twitter](https://twitter.com/yee2079): Follow on Twitter