ERC-721 Enumerable Mint Module
Mint ERC-721 tokens and manage enumeration lists
- Internal functions for minting and enumeration management.
- Uses diamond storage pattern (EIP-8042) for shared state.
- Enforces ERC-721 token existence checks.
- Emits
Transferevent upon successful minting.
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 to mint ERC-721 tokens and maintain enumeration lists within a diamond. Facets can import this module to handle token creation and ensure that all minted tokens are tracked, making them accessible to other facets via shared diamond storage. This facilitates consistent state management across the diamond.
Storage
ERC721EnumerableStorage
storage-location: erc8042:erc721.enumerable
ERC721Storage
storage-location: erc8042:erc721
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
getERC721Storage
Returns a pointer to the ERC-721 storage struct. Uses inline assembly to access the storage slot defined by STORAGE_POSITION.
Returns:
| Property | Type | Description |
|---|---|---|
s | ERC721Storage | The ERC721Storage struct in storage. |
getStorage
Returns the storage struct used by this facet.
Returns:
| Property | Type | Description |
|---|---|---|
s | ERC721EnumerableStorage | The ERC721Enumerable storage struct. |
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. |
Events
Errors
Best Practices
- Ensure the
toaddress is not the zero address before callingmint. - Verify that the
tokenIddoes not already exist in storage to prevent re-minting. - Call
mintonly after confirming necessary access controls are met by the calling facet.
Integration Notes
This module interacts with diamond storage at the STORAGE_POSITION defined by keccak256(\"erc721.enumerable\"). The mint function reads from and writes to the ERC721EnumerableStorage struct, ensuring that newly minted tokens are added to internal enumeration lists. Changes to this storage are immediately visible to all facets operating on the same diamond storage layout.