ERC-721 Mint Module
Mint ERC-721 tokens using diamond storage
- Exposes
internalmintfunction for facet integration. - Utilizes diamond storage pattern (EIP-8042) for state management.
- Emits
Transferevent upon successful minting. - No external dependencies, ensuring minimal on-chain footprint.
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 new ERC-721 tokens. Facets can import this module to manage token creation, leveraging shared diamond storage for consistency. Changes made via this module are immediately visible to all facets sharing the same storage.
Storage
ERC721Storage
State Variables
| Property | Type | Description |
|---|---|---|
STORAGE_POSITION | bytes32 | Diamond storage slot position for this module (Value: keccak256("erc721")) |
Functions
getStorage
Returns the ERC-721 storage struct from its predefined slot. Uses inline assembly to access diamond storage location.
Returns:
| Property | Type | Description |
|---|---|---|
s | ERC721Storage | The storage reference for ERC-721 state variables. |
mint
Mints a new ERC-721 token to the specified address. 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 calling facet enforces access control before invoking
mint. - Verify the
toaddress is not the zero address and thetokenIddoes not already exist before callingmint. - Handle
ERC721InvalidReceiverand other potential errors gracefully.
Integration Notes
This module accesses shared diamond storage at the position identified by keccak256(\"erc721\") to manage ERC-721 token state. The mint function reads and writes to this shared storage. Any facet that also accesses this storage slot will observe changes made by this module immediately. The ERC721Storage struct, though empty in this definition, reserves the storage slot for future ERC-721 specific state.