Skip to main content

ERC-721 Metadata Facet

ERC-721 token metadata retrieval for diamonds

Key Features
  • 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

Definition
struct ERC721MetadataStorage {
string name;
string symbol;
string baseURI;
}

ERC721Storage

Definition
struct ERC721Storage {
mapping(uint256 tokenId => address owner) ownerOf;
mapping(address owner => uint256 balance) balanceOf;
mapping(address owner => mapping(address operator => bool approved)) isApprovedForAll;
mapping(uint256 tokenId => address approved) approved;
}

State Variables

PropertyTypeDescription
STORAGE_POSITIONbytes32Diamond storage slot position for this module (Value: keccak256("erc721.metadata"))
ERC721_STORAGE_POSITIONbytes32Diamond storage slot position for this module (Value: keccak256("erc721"))

Functions

name

Returns the token collection name.

function name() external view returns (string memory);

Returns:

PropertyTypeDescription
-stringThe name of the token collection.

symbol

Returns the token collection symbol.

function symbol() external view returns (string memory);

Returns:

PropertyTypeDescription
-stringThe symbol of the token collection.

tokenURI

Provide the metadata URI for a given token ID.

function tokenURI(uint256 _tokenId) external view returns (string memory);

Parameters:

PropertyTypeDescription
_tokenIduint256tokenID of the NFT to query the metadata from

Returns:

PropertyTypeDescription
-stringthe 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

function exportSelectors() external pure returns (bytes memory);

Returns:

PropertyTypeDescription
-bytesselectors The exported function selectors of the ERC721MetadataFacet

Errors

Best Practices

Best Practice
  • Ensure the ERC721MetadataFacet is added to the diamond with the correct selectors.
  • Call name(), symbol(), and tokenURI() through the diamond proxy address.
  • Verify storage slot compatibility if upgrading or adding facets that interact with ERC-721 storage.

Security Considerations

Security

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.

Was this helpful?
Last updated:

Newsletter

Get notified about releases, feature announcements, and technical deep-dives on building smart contracts with Compose.

No spam. Unsubscribe anytime.