ERC-1155 Mint Module
ERC-1155 token minting and batch minting
- Internal functions for direct integration into custom facets.
- Utilizes the diamond storage pattern (EIP-8042) for shared state.
- Emits
TransferSingleandTransferBatchevents for off-chain tracking. - Includes recipient validation for contract addresses.
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 minting ERC-1155 tokens. Facets can import this module to manage token creation directly within the diamond, leveraging shared diamond storage for balances. Changes to token balances are immediately visible to all facets accessing the same storage slot.
Storage
ERC1155Storage
ERC-8042 compliant storage struct for ERC-1155 token data. storage-location: erc8042:erc1155
State Variables
| Property | Type | Description |
|---|---|---|
STORAGE_POSITION | bytes32 | Diamond storage slot position for this module (Value: keccak256("erc1155")) |
Functions
getStorage
Returns the ERC-1155 storage struct from the predefined diamond storage slot. Uses inline assembly to set the storage slot reference.
Returns:
| Property | Type | Description |
|---|---|---|
s | ERC1155Storage | The ERC-1155 storage struct reference. |
mint
Mints a single token type to an address. Increases the balance and emits a TransferSingle event. Performs receiver validation if recipient is a contract.
Parameters:
| Property | Type | Description |
|---|---|---|
_to | address | The address that will receive the tokens. |
_id | uint256 | The token type to mint. |
_value | uint256 | The amount of tokens to mint. |
_data | bytes | Additional data with no specified format. |
mintBatch
Mints multiple token types to an address in a single transaction. Increases balances for each token type and emits a TransferBatch event. Performs receiver validation if recipient is a contract.
Parameters:
| Property | Type | Description |
|---|---|---|
_to | address | The address that will receive the tokens. |
_ids | uint256[] | The token types to mint. |
_values | uint256[] | The amounts of tokens to mint for each type. |
_data | bytes | Additional data with no specified format. |
Events
Errors
Best Practices
- Ensure the recipient address is validated for contract calls to prevent reentrancy issues.
- Verify that the array lengths for
mintBatchmatch to avoidERC1155InvalidArrayLengtherrors. - Handle potential
ERC1155InvalidReceivererrors when minting to contract addresses.
Integration Notes
This module interacts with diamond storage at the slot identified by keccak256(\"erc1155\"). The getStorage() function returns a reference to the ERC1155Storage struct. All minting operations directly modify balances within this shared storage, making changes immediately visible to other facets that access the same storage slot.