ERC-721 Enumerable Transfer Facet
ERC-721 token transfers within a diamond
- Exposes external functions for diamond routing of ERC-721 transfers.
- Accesses shared ERC-721 state via diamond storage.
- Supports standard ERC-721 transfer and safe transfer operations.
- Includes a mechanism (
exportSelectors) for diamond selector discovery.
Overview
This facet implements ERC-721 token transfers as external functions in a diamond. It routes calls through the diamond proxy and accesses shared storage via ERC721Storage. Developers add this facet to expose token transfer functionality while maintaining upgradeability.
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
transferFrom
Transfers a token from one address to another.
Parameters:
| Property | Type | Description |
|---|---|---|
_from | address | The current owner of the token. |
_to | address | The recipient address. |
_tokenId | uint256 | The token ID to transfer. |
safeTransferFrom
Safely transfers a token, checking for receiver contract compatibility.
Parameters:
| Property | Type | Description |
|---|---|---|
_from | address | The current owner of the token. |
_to | address | The recipient address. |
_tokenId | uint256 | The token ID to transfer. |
safeTransferFrom
Safely transfers a token with additional data.
Parameters:
| Property | Type | Description |
|---|---|---|
_from | address | The current owner of the token. |
_to | address | The recipient address. |
_tokenId | uint256 | The token ID to transfer. |
_data | bytes | Additional data to send to the receiver contract. |
exportSelectors
Exports the function selectors of the ERC721EnumerableTransferFacet This function is use as a selector discovery mechanism for diamonds
Returns:
| Property | Type | Description |
|---|---|---|
- | bytes | selectors The exported function selectors of the ERC721EnumerableTransferFacet |
Events
Errors
Best Practices
- Ensure the
ERC721Storagestruct is properly initialized and accessible by this facet. - Verify that other facets do not interfere with the token ownership state managed by this facet.
- Call
transferFrom,safeTransferFromfunctions through the diamond proxy address.
Security Considerations
The transferFrom and safeTransferFrom functions handle token ownership transfers. Reentrancy is mitigated by the checks-effects-interactions pattern. Input validation is crucial; ensure token IDs are valid and ownership rules are respected. Errors ERC721NonexistentToken, ERC721IncorrectOwner, ERC721InvalidReceiver, and ERC721InsufficientApproval are used to revert on invalid operations. The safeTransferFrom variations include checks for receiver contract compatibility.