ERC-721 Data Facet
ERC-721 token data retrieval functions for diamonds
- Exposes external view functions for ERC-721 token data.
- Accesses shared diamond storage via
getStorageinternal function. - Supports ERC-721 data querying patterns like
ownerOf,balanceOf,getApproved, andisApprovedForAll. - Provides
exportSelectorsfor diamond facet discovery.
Overview
This facet provides external view functions for retrieving ERC-721 token ownership and approval data within a diamond. It accesses shared diamond storage to provide these details, enabling other facets or external contracts to query token information without direct storage access. Developers integrate this facet to expose standard ERC-721 data queries through the diamond proxy interface.
Storage
ERC721Storage
State Variables
| Property | Type | Description |
|---|---|---|
STORAGE_POSITION | bytes32 | Diamond storage slot position for this module (Value: keccak256("erc721")) |
Functions
balanceOf
Returns the number of tokens owned by a given address.
Parameters:
| Property | Type | Description |
|---|---|---|
_owner | address | The address to query the balance of. |
Returns:
| Property | Type | Description |
|---|---|---|
- | uint256 | The balance (number of tokens) owned by _owner. |
ownerOf
Returns the owner of a given token ID.
Parameters:
| Property | Type | Description |
|---|---|---|
_tokenId | uint256 | The token ID to query. |
Returns:
| Property | Type | Description |
|---|---|---|
- | address | The address of the token owner. |
getApproved
Returns the approved address for a given token ID.
Parameters:
| Property | Type | Description |
|---|---|---|
_tokenId | uint256 | The token ID to query the approval of. |
Returns:
| Property | Type | Description |
|---|---|---|
- | address | The approved address for the token. |
isApprovedForAll
Returns true if an operator is approved to manage all of an owner's assets.
Parameters:
| Property | Type | Description |
|---|---|---|
_owner | address | The token owner. |
_operator | address | The operator address. |
Returns:
| Property | Type | Description |
|---|---|---|
- | bool | True if the operator is approved for all tokens of the owner. |
exportSelectors
Exports the function selectors of the ERC721DataFacet This function is use as a selector discovery mechanism for diamonds
Returns:
| Property | Type | Description |
|---|---|---|
- | bytes | selectors The exported function selectors of the ERC721DataFacet |
Errors
Best Practices
- Ensure the ERC721DataFacet is correctly registered with the diamond's facet registry.
- Always call functions like
ownerOfandbalanceOfthrough the diamond proxy address. - Verify that the
ERC721Storagestruct is correctly initialized and populated by other facets before querying.
Security Considerations
This facet primarily exposes view functions and does not perform state modifications. Ensure that the underlying ERC721Storage is managed securely by other facets. The ownerOf and balanceOf functions revert with ERC721NonexistentToken if the token ID does not exist, and ownerOf reverts with ERC721InvalidOwner if the owner address is zero. Input validation for token IDs and addresses is handled by the facet.