Skip to main content

ERC-1155 Burn Facet

Burn ERC-1155 tokens within a diamond

Key Features
  • Provides external functions for burning single and batch ERC-1155 tokens.
  • Leverages diamond storage for token balances and operator approvals.
  • Emits TransferSingle and TransferBatch events upon successful burns.
  • Includes exportSelectors for facet discovery within a diamond.

Overview

This facet provides external functions for burning ERC-1155 tokens within a Compose diamond. It routes calls through the diamond proxy, accesses shared storage via getStorage, and emits standard ERC-1155 transfer events. Developers add this facet to enable token burning functionality while maintaining diamond upgradeability.

Storage

ERC1155Storage

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. Emits a TransferSingle event. Caller must be the owner or an approved operator.

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

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. Emits a TransferBatch event. Caller must be the owner or an approved operator.

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

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.

exportSelectors

Exports the function selectors of the ERC1155BurnFacet This function is use as a selector discovery mechanism for diamonds

function exportSelectors() external pure returns (bytes memory);

Returns:

PropertyTypeDescription
-bytesselectors The exported function selectors of the ERC1155BurnFacet

Events

Errors

Best Practices

Best Practice
  • Ensure the ERC1155BurnFacet is properly initialized with correct storage slot.
  • Caller must possess the token or be an approved operator before calling burn functions.
  • Verify that _ids and _values arrays have matching lengths before calling burnBatch.

Security Considerations

Security

The burn and burnBatch functions require the caller to be the owner of the tokens or an approved operator. Insufficient balance will revert with ERC1155InsufficientBalance. Mismatched array lengths in burnBatch will revert with ERC1155InvalidArrayLength. Ensure that the diamond's access control mechanism correctly routes calls and that token ownership logic is consistent across all relevant facets.

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.