This specification standardizes contractURI() to return contract-level metadata. This is useful for dapps and offchain indexers to show rich information about a contract, such as its name, description and image, without specifying it manually or individually for each dapp.
Motivation
Dapps have included supported for contractURI() for years without an ERC to reference. This standard also introduces the event ContractURIUpdated() to signal when to update the metadata.
Specification
The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “NOT RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in RFC 2119 and RFC 8174.
The string returned from contractURI() MAY be an offchain resource or onchain JSON data string (data:application/json;utf8,{}).
The ContractURIUpdated() event SHOULD be emitted on updates to the contract metadata for offchain indexers to query the contract.
If the underlying contract provides any methods that conflict with the contractURI schema such as name() or symbol(), the metadata returned by contractURI() is RECOMMENDED to take precedence. This enables contract creators to update their contract details with an event that notifies of the update.
Schema for contractURI
The schema for the JSON returned from contractURI() MUST conform to:
{"$schema":"https://json-schema.org/draft/2020-12/schema","type":"object","properties":{"name":{"type":"string","description":"The name of the contract."},"symbol":{"type":"string","description":"The symbol 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."},"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"]}
Future ERCs MAY inherit this one to add more properties to the schema for standardization.
Rationale
The method name contractURI() was chosen based on its existing implementation in dapps. The event ContractURIUpdated() is specified to help offchain indexers to know when to refetch the metadata.
Backwards Compatibility
As a new ERC, no backwards compatibility issues are present.
Reference Implementation
contractMyCollectibleisERC721,IERCXXXX{string_contractURI="ipfs://QmTNgv3jx2HHfBjQX9RnKtxj2xv2xQDtbVXoRi5rJ3a46e"// or e.g. "https://external-link-url.com/my-contract-metadata.json";
functioncontractURI()externalviewreturns(stringmemory){return_contractURI;// or e.g. for onchain:
stringmemoryjson='{"name": "Creatures","description":"..."}';returnstring.concat("data:application/json;utf8,",json);}/// @dev Suggested setter, not explicitly specified as part of this ERC
functionsetContractURI(stringmemorynewURI)externalonlyOwner{_contractURI=newURI;emitContractURIUpdated();}}
Security Considerations
Addresses specified as collaborators should be expected to receive admin-level functionality for updating contract information on dapps that implement this standard.