We don't specify any special requirements for common Unique collections. But ERC721-compatible collections MUST meet these requirements:
-
Collection's flag
erc721metadataMUST betrue// getting flags not available in solidity interfaces right now -
Collection MAY have property
{key: "baseURI", value: "<base URI of the tokens>"} -
Collection MUST have such tokenPropertyPermission:
{key: "URI", permission: {mutable: true, collectionAdmin: true, tokenOwner: false}}- token full URI -
Collection MAY have such tokenPropertyPermission:
{key: "URISuffix", permission: {mutable: true, collectionAdmin: true, tokenOwner: false}}- token URI suffix
UniqueNFT stub interface has to contain such functions:
function supportsInterface(bytes4 interfaceID) external view returns (bool);
When called with interfaceID 0x5b5e139f (ERC721Metadata), it MUST return true if collection's flag erc721metadata is true, otherwise false.
Other interfaceID values are assumed to be processed as usual.
function tokenURI(uint256 tokenId) public view virtual override returns (string memory);
Definitions:
- "baseURI is non-empty" means that there is a property in the collection with key
"baseURI"and value which IS NOT empty string. - "URI is non-empty" means that there is a property in the token with key
"URI"and value which IS NOT empty string. - "URISuffix is non-empty" means that there is a property in the token with key
"URISuffix"and value which IS NOT empty string. In other words, whenbaseURIandURIandsis empty string,tokenURIfunction MUST consider it as absence of this property at all.
In other words, reading of token properties URI and URISuffix should be safe and don't throw if there is no such tokenPropertyPermission.
Desired behaviour:
if the collections has flag erc721metadata value not true, throw an error.
Otherwise,
- if token property
URI(safe property read) is non-empty, return it, token propertyURI - otherwise, if the collection property
baseURIis empty or absent, return "" (empty string) - otherwise, if token property
URISuffix(safe property read) is non-empty, return concatenation of collection propertybaseURIand token propertyURISuffix - otherwise, return collection property
baseURI
Example in pseudocode:
let isCollectionERC721MetadataCompatible = collection.flags.erc721metadata === true
let baseURI = collectionProperty("baseURI")
let URI = tokenProperty(tokenId, "URI")
let URISuffix = tokenProperty(tokenId, "URISuffix")
let baseURIIsOk = !!baseURI && baseURI.length > 0
let URIIsOk = !!URI && URI.length > 0
let suffixIsOk = !!URISuffix && URISuffix.length > 0
if (!isCollectionERC721MetadataCompatible) {
throw;
} else if (URIIsOk) {
return URI;
} else if (!baseURIIsOk) {
return "";
} else if (suffixIsOk) {
return baseURI + URISuffix;
} else {
return baseURI;
}
A bit simpler implementation can be found here: ERC721URIStorage tokenURI implementation