ERC1155Mod
Handles ERC-1155 token minting, burning, and transfers
- Internal functions for minting, burning, and transfers.
- Supports safe transfers for ERC-1155 token contracts.
- Manages token URIs with
setBaseURIandsetTokenURIfunctions. - Utilizes diamond storage for state management.
This module provides internal functions for use in your custom facets. Import it to access shared logic and storage.
Overview
This module provides core ERC-1155 functionality including minting, burning, and safe transfers. Facets can integrate this module to manage ERC-1155 tokens within the diamond, leveraging shared diamond storage for token balances and URIs. It ensures interoperability by adhering to EIP-1155 standards for safe transfers.
Storage
ERC1155Storage
ERC-8042 compliant storage struct for ERC-1155 token data. storage-location: erc8042:compose.erc1155
State Variables
| Property | Type | Description |
|---|---|---|
STORAGE_POSITION | bytes32 | Diamond storage slot position for this module (Value: keccak256("compose.erc1155")) |
Functions
burn
Burns a single token type from an address. Decreases the balance and emits a TransferSingle event. Reverts if the account has insufficient balance.
Parameters:
| Property | Type | Description |
|---|---|---|
_from | address | The address whose tokens will be burned. |
_id | uint256 | The token type to burn. |
_value | uint256 | The amount of tokens to burn. |
burnBatch
Burns multiple token types from an address in a single transaction. Decreases balances for each token type and emits a TransferBatch event. Reverts if the account has insufficient balance for any token type.
Parameters:
| Property | Type | Description |
|---|---|---|
_from | address | The address whose tokens will be burned. |
_ids | uint256[] | The token types to burn. |
_values | uint256[] | The amounts of tokens to burn for each type. |
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. |
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. |
safeBatchTransferFrom
Safely transfers multiple token types from one address to another in a single transaction. Validates ownership, approval, and receiver address before updating balances for each token type. Performs ERC1155Receiver validation if recipient is a contract (safe transfer). Complies with EIP-1155 safe transfer requirements.
Parameters:
| Property | Type | Description |
|---|---|---|
_from | address | The address to transfer from. |
_to | address | The address to transfer to. |
_ids | uint256[] | The token types to transfer. |
_values | uint256[] | The amounts of tokens to transfer for each type. |
_operator | address | The address initiating the transfer (may be owner or approved operator). |
safeTransferFrom
Safely transfers a single token type from one address to another. Validates ownership, approval, and receiver address before updating balances. Performs ERC1155Receiver validation if recipient is a contract (safe transfer). Complies with EIP-1155 safe transfer requirements.
Parameters:
| Property | Type | Description |
|---|---|---|
_from | address | The address to transfer from. |
_to | address | The address to transfer to. |
_id | uint256 | The token type to transfer. |
_value | uint256 | The amount of tokens to transfer. |
_operator | address | The address initiating the transfer (may be owner or approved operator). |
setBaseURI
Sets the base URI prefix for token-specific URIs. The base URI is concatenated with token-specific URIs set via setTokenURI. Does not affect the default URI used when no token-specific URI is set.
Parameters:
| Property | Type | Description |
|---|---|---|
_baseURI | string | The base URI string to prepend to token-specific URIs. |
setTokenURI
Sets the token-specific URI for a given token ID. Sets tokenURIs[_tokenId] to the provided string and emits a URI event with the full computed URI. The emitted URI is the concatenation of baseURI and the token-specific URI.
Parameters:
| Property | Type | Description |
|---|---|---|
_tokenId | uint256 | The token ID to set the URI for. |
_tokenURI | string | The token-specific URI string to be concatenated with baseURI. |
Events
Errors
Best Practices
- Call
safeTransferFromorsafeBatchTransferFromfor standard ERC-1155 transfers to ensure receiver contract compatibility. - Use
mintandburnfunctions for internal token lifecycle management. - Ensure correct
_operatoris passed for transfers to maintain accurate approval tracking.
Integration Notes
This module utilizes the diamond storage pattern, storing ERC-1155 state within a dedicated slot identified by keccak256(\"compose.erc1155\"). The ERC1155Storage struct, containing uri and baseURI fields, is managed at this position. Functions like mint, burn, and transfers directly interact with this shared storage, ensuring all facets accessing this storage see consistent token balances and URI information.