Skip to main content

ERC-1155 Mint Module

ERC-1155 token minting and batch minting

Key Features
  • Internal functions for direct integration into custom facets.
  • Utilizes the diamond storage pattern (EIP-8042) for shared state.
  • Emits TransferSingle and TransferBatch events for off-chain tracking.
  • Includes recipient validation for contract addresses.
Module Usage

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

Definition
struct ERC1155Storage {
mapping(uint256 id => mapping(address account => uint256 balance)) balanceOf;
mapping(address account => mapping(address operator => bool)) isApprovedForAll;
}

State Variables

PropertyTypeDescription
STORAGE_POSITIONbytes32Diamond 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.

function getStorage() pure returns (ERC1155Storage storage s);

Returns:

PropertyTypeDescription
sERC1155StorageThe 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.

function mint(address _to, uint256 _id, uint256 _value, bytes memory _data) ;

Parameters:

PropertyTypeDescription
_toaddressThe address that will receive the tokens.
_iduint256The token type to mint.
_valueuint256The amount of tokens to mint.
_databytesAdditional 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.

function mintBatch(address _to, uint256[] memory _ids, uint256[] memory _values, bytes memory _data) ;

Parameters:

PropertyTypeDescription
_toaddressThe address that will receive the tokens.
_idsuint256[]The token types to mint.
_valuesuint256[]The amounts of tokens to mint for each type.
_databytesAdditional data with no specified format.

Events

Errors

Best Practices

Best Practice
  • Ensure the recipient address is validated for contract calls to prevent reentrancy issues.
  • Verify that the array lengths for mintBatch match to avoid ERC1155InvalidArrayLength errors.
  • Handle potential ERC1155InvalidReceiver errors when minting to contract addresses.

Integration Notes

Shared Storage

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.

Was this helpful?
Last updated:

Newsletter

Get notified about releases, feature announcements, and technical deep-dives on building smart contracts with Compose.

No spam. Unsubscribe anytime.