ERC-721 Metadata Facet
ERC-721 token metadata retrieval for diamonds
- Exposes external view functions for metadata retrieval.
- Accesses shared diamond storage for name, symbol, and base URI.
- Functions are routed through the diamond proxy.
- Compatible with ERC-2535 diamond standard.
Overview
This facet provides external view functions for retrieving ERC-721 token metadata, such as name, symbol, and token URIs, within a Compose diamond. It accesses shared diamond storage to ensure consistency across facets. Developers integrate this facet to expose token metadata directly through the diamond proxy.
Storage
ERC721MetadataStorage
ERC721Storage
State Variables
| Property | Type | Description |
|---|---|---|
STORAGE_POSITION | bytes32 | Diamond storage slot position for this module (Value: keccak256("erc721.metadata")) |
ERC721_STORAGE_POSITION | bytes32 | Diamond storage slot position for this module (Value: keccak256("erc721")) |
Functions
name
Returns the token collection name.
Returns:
| Property | Type | Description |
|---|---|---|
- | string | The name of the token collection. |
symbol
Returns the token collection symbol.
Returns:
| Property | Type | Description |
|---|---|---|
- | string | The symbol of the token collection. |
tokenURI
Provide the metadata URI for a given token ID.
Parameters:
| Property | Type | Description |
|---|---|---|
_tokenId | uint256 | tokenID of the NFT to query the metadata from |
Returns:
| Property | Type | Description |
|---|---|---|
- | string | the URI providing the detailed metadata of the specified tokenID |
exportSelectors
Exports the function selectors of the ERC721MetadataFacet This function is use as a selector discovery mechanism for diamonds
Returns:
| Property | Type | Description |
|---|---|---|
- | bytes | selectors The exported function selectors of the ERC721MetadataFacet |
Errors
Best Practices
- Ensure the
ERC721MetadataFacetis added to the diamond with the correct selectors. - Call
name(),symbol(), andtokenURI()through the diamond proxy address. - Verify storage slot compatibility if upgrading or adding facets that interact with ERC-721 storage.
Security Considerations
The tokenURI function reverts with ERC721NonexistentToken if the provided _tokenId does not exist within the diamond's state. Input validation for _tokenId is crucial. Access to metadata is read-only and does not pose reentrancy risks. Follow standard Solidity security practices for diamond interactions.