Skip to main content

ERC-1155 Burn Module

Internal ERC-1155 token burning functionality

Key Features
  • All functions are internal for use within custom facets.
  • Utilizes the diamond storage pattern for shared state management.
  • Emits TransferSingle and TransferBatch events upon successful burns.
  • Reverts with custom errors for insufficient balance or invalid array lengths.
Module Usage

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

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

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.

function burn(address _from, uint256 _id, uint256 _value) ;

Parameters:

PropertyTypeDescription
_fromaddressThe address whose tokens will be burned.
_iduint256The token type to burn.
_valueuint256The 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.

function burnBatch(address _from, uint256[] memory _ids, uint256[] memory _values) ;

Parameters:

PropertyTypeDescription
_fromaddressThe address whose tokens will be burned.
_idsuint256[]The token types to burn.
_valuesuint256[]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.

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

Returns:

PropertyTypeDescription
sERC1155StorageThe ERC-1155 storage struct reference.

Events

Errors

Best Practices

Best Practice
  • Ensure caller has necessary permissions (e.g., ownership, operator approval) before calling burn functions.
  • Verify that _ids and _values arrays have matching lengths when calling burnBatch.
  • Handle the ERC1155InsufficientBalance error that may be returned if the sender does not possess enough tokens.

Integration Notes

Shared Storage

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.

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.