ERC-721 Enumerable Data Facet
Enumerable ERC-721 token data retrieval
- Exposes external functions for enumerable ERC-721 data retrieval via diamond proxy.
- Reads from shared diamond storage without modifying state.
- Supports querying total supply and specific tokens by index or owner.
- Utilizes inline assembly for efficient storage access.
Overview
This facet provides external functions for retrieving enumerable ERC-721 token data from a diamond. It accesses shared storage to return total token supply and specific token IDs by index or owner. Developers add this facet to enable querying of token ownership and enumeration within a diamond.
Storage
ERC721EnumerableStorage
ERC721Storage
State Variables
| Property | Type | Description |
|---|---|---|
STORAGE_POSITION | bytes32 | Diamond storage slot position for this module (Value: keccak256("erc721.enumerable")) |
ERC721_STORAGE_POSITION | bytes32 | Diamond storage slot position for this module (Value: keccak256("erc721")) |
Functions
totalSupply
Returns the total number of tokens in existence.
Returns:
| Property | Type | Description |
|---|---|---|
- | uint256 | The total supply of tokens. |
tokenOfOwnerByIndex
Returns a token ID owned by a given address at a specific index.
Parameters:
| Property | Type | Description |
|---|---|---|
_owner | address | The address to query. |
_index | uint256 | The index of the token. |
Returns:
| Property | Type | Description |
|---|---|---|
- | uint256 | The token ID owned by _owner at _index. |
tokenByIndex
Enumerate valid NFTs Throws if _index >= totalSupply().
Parameters:
| Property | Type | Description |
|---|---|---|
_index | uint256 | A counter less than totalSupply() |
Returns:
| Property | Type | Description |
|---|---|---|
- | uint256 | The token identifier for the _indexth NFT, |
exportSelectors
Exports the function selectors of the ERC721EnumerableDataFacet This function is use as a selector discovery mechanism for diamonds
Returns:
| Property | Type | Description |
|---|---|---|
- | bytes | selectors The exported function selectors of the ERC721EnumerableDataFacet |
Errors
Best Practices
- Ensure the
ERC721EnumerableDataFacetis added to the diamond and its selectors are correctly registered. - When calling
tokenOfOwnerByIndexortokenByIndex, validate the provided index againsttotalSupply()to preventERC721OutOfBoundsIndexerrors. - This facet only reads from shared storage; ensure other facets managing token state maintain storage invariants.
Security Considerations
The tokenByIndex function reverts if _index is out of bounds, indicated by the ERC721OutOfBoundsIndex error. All functions are view and do not pose reentrancy risks. Access control is implicitly handled by the diamond proxy routing calls to this facet.