ERC721EnumerableMod
Internal logic for enumerable ERC-721 tokens
- Exposes
internalfunctions for mint, burn, and transfer operations. - Integrates with the diamond storage pattern via a predefined storage slot.
- Utilizes custom errors for gas-efficient error reporting.
- No external dependencies or
usingdirectives, promoting composability.
This module provides internal functions for use in your custom facets. Import it to access shared logic and storage.
Overview
This module provides internal functions for managing enumerable ERC-721 tokens using the diamond storage pattern. Facets can import this module to implement minting, burning, and transfer logic while maintaining token enumeration order. Changes made through this module are immediately visible to all facets accessing the shared storage.
Storage
ERC721EnumerableStorage
State Variables
| Property | Type | Description |
|---|---|---|
STORAGE_POSITION | bytes32 | Diamond storage slot position for this module (Value: keccak256("compose.erc721.enumerable")) |
Functions
burn
Burns (destroys) an existing ERC-721 token, removing it from enumeration lists. Reverts if the token does not exist or if the sender is not authorized.
Parameters:
| Property | Type | Description |
|---|---|---|
_tokenId | uint256 | The ID of the token to burn. |
_sender | address | The address initiating the burn. |
getStorage
Returns the ERC-721 enumerable storage struct from its predefined slot. Uses inline assembly to point to the correct diamond storage position.
Returns:
| Property | Type | Description |
|---|---|---|
s | ERC721EnumerableStorage | The storage reference for ERC-721 enumerable state variables. |
mint
Mints a new ERC-721 token to the specified address, adding it to enumeration lists. Reverts if the receiver address is zero or if the token already exists.
Parameters:
| Property | Type | Description |
|---|---|---|
_to | address | The address that will own the newly minted token. |
_tokenId | uint256 | The ID of the token to mint. |
transferFrom
Transfers a token ID from one address to another, updating enumeration data. Validates ownership, approval, and receiver address before state updates.
Parameters:
| Property | Type | Description |
|---|---|---|
_from | address | The current owner of the token. |
_to | address | The address receiving the token. |
_tokenId | uint256 | The ID of the token being transferred. |
_sender | address | The initiator of the transfer (may be owner or approved operator). |
Events
Errors
Best Practices
- Ensure the
ERC721EnumerableModis correctly initialized with the diamond's storage pointer. - Verify ownership and approval checks are performed by the calling facet before invoking
transferFromorburn. - Handle potential errors like
ERC721NonexistentTokenorERC721IncorrectOwnerin facet logic.
Integration Notes
This module reads and writes to diamond storage at the position identified by keccak256(\"compose.erc721.enumerable\"). The ERC721EnumerableStorage struct, containing state like token name, symbol, and base URI, is managed at this slot. All functions are internal and directly interact with this shared storage, making changes immediately visible to any facet accessing the same storage position.