ERC-1155 Burn Module
Internal ERC-1155 token burning functionality
- All functions are
internalfor use within custom facets. - Utilizes the diamond storage pattern for shared state management.
- Emits
TransferSingleandTransferBatchevents upon successful burns. - Reverts with custom errors for insufficient balance or invalid array lengths.
This module provides internal functions for use in your custom facets. Import it to access shared logic and storage.
Overview
This module exposes internal functions for burning ERC-1155 tokens. Facets can import this module to decrease token balances using shared diamond storage. Changes made through this module are immediately visible to all facets using the same storage pattern.
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
burn
Burns a single token type from an address. Decreases the balance and emits a TransferSingle event. Reverts if the account has insufficient balance. This module does not perform approval checks. Ensure proper ownership or approval validation before calling this function.
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. This module does not perform approval checks. Ensure proper ownership or approval validation before calling this function.
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. |
Events
Errors
Best Practices
- Ensure caller has necessary permissions (e.g., ownership, operator approval) before calling burn functions.
- Verify that
_idsand_valuesarrays have matching lengths when callingburnBatch. - Handle the
ERC1155InsufficientBalanceerror that may be returned if the sender does not possess enough tokens.
Integration Notes
This module interacts with diamond storage at the position identified by keccak256("erc1155"). The ERC1155Storage struct, though empty in its definition, resides at this slot. All state modifications (balance reductions) are performed directly on this shared storage, making them immediately visible to any other facet accessing the same storage slot. The getStorage function can be used to retrieve a reference to this storage struct.