ERC7572
컨트랙트의 메타데이터를 제공하는 contractURI 함수를 추가한다. 주로 NFT에서 사용한다.
interface IERC7572 {
function contractURI() external view returns (string memory);
event ContractURIUpdated();
}contractURI 함수에서는 메타데이터의 URI 또는 직접 메타데이터를 리턴할 수 있다. 메타데이터는 JSON 형식으로 작성한다. name 필드는 필수이며, 나머지 필드는 각 타입과 용도에 맞춰 작성한다.
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "The name of the contract."
},
"description": {
"type": "string",
"description": "The description of the contract."
},
"image": {
"type": "string",
"format": "uri",
"description": "A URI pointing to a resource with mime type image/* that represents the contract, typically displayed as a profile picture for the contract."
},
"banner_image": {
"type": "string",
"format": "uri",
"description": "A URI pointing to a resource with mime type image/* that represents the contract, displayed as a banner image for the contract."
},
"featured_image": {
"type": "string",
"format": "uri",
"description": "A URI pointing to a resource with mime type image/* that represents the featured image for the contract, typically used for a highlight section. The aspect ratio of the image should be 1:1."
},
"external_link": {
"type": "string",
"format": "uri",
"description": "The external link of the contract."
},
"collaborators": {
"type": "array",
"items": {
"type": "string",
"description": "An Ethereum address representing an authorized editor of the contract."
},
"description": "An array of Ethereum addresses representing collaborators (authorized editors) of the contract."
}
},
"required": ["name"]
}예를 들어 다음과 같다.
{
"name": "Example Contract",
"description": "Your description here",
"image": "ipfs://QmTNgv3jx2HHfBjQX9RnKtxj2xv2xQCtbDXoRi5rJ3a46e",
"banner_image": "ipfs://QmdChMVnMSq4U7oVKhud7wUSEZGnwuMuTY5rUQx57Ayp6H",
"featured_image": "ipfs://QmS9m6e1E1NfioMM8dy1WMZNN2FRh2WDjeqJFWextqXCT8",
"external_link": "https://project-website.com",
"collaborators": ["0x388C818CA8B9251b393131C08a736A67ccB19297"]
}온체인에서 직접 JSON을 리턴할 시 데이터 맨 앞에 data:application/json;utf8, 를 붙여주는 것을 잊지 말자.
contract MyCollectible is ERC721 {
function contractURI() public pure returns (string memory) {
string memory json = '{"name": "Opensea Creatures","description":"..."}';
@> return string.concat("data:application/json;utf8,", json);
}
}MUST
- IERC7572 인터페이스를 반드시 구현해야 한다. (
contractURI함수와ContractURIUpdated이벤트) - 리턴되는 JSON의 형식은 반드시 위에서 언급한 포맷을 따라야 한다.
SHOULD
- 업데이트 시마다
ContractURIUpdated이벤트를 발생시켜 오프체인 인덱서가 쿼리할 수 있도록 한다.
RECOMMENDED
- 컨트랜트가
name()함수를 따로 제공하고 있다면,contractURI()에서 리턴하는 name 필드를 우선하는 것이 좋다.
MAY
contractURI함수는 오프체인 리소스의 URL일 수도 있고, 온체인에서 JSON 데이터를 리턴할 수도 있다.data:application/json;utf8,{}
tags: blockchain, smart contract, erc721, erc1155, nft