Skip to main content

ERC-721 Enumerable Burn Module

Destroys ERC-721 tokens and removes them from enumeration

Key Features
  • Exposes an internal function for burning tokens.
  • Integrates with diamond storage to remove tokens from enumeration.
  • Emits a Transfer event upon successful burning.
  • Does not perform approval checks; relies on the calling facet for this.
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 an internal function to burn ERC-721 tokens, removing them from enumeration tracking. Facets can integrate this module to handle token destruction directly within the diamond's shared storage. This ensures that token removal is consistent across all facets interacting with the ERC-721 state.

Storage

ERC721EnumerableStorage

storage-location: erc8042:erc721.enumerable

Definition
struct ERC721EnumerableStorage {
mapping(address owner => mapping(uint256 index => uint256 tokenId)) ownerTokens;
mapping(uint256 tokenId => uint256 ownerTokensIndex) ownerTokensIndex;
uint256[] allTokens;
mapping(uint256 tokenId => uint256 allTokensIndex) allTokensIndex;
}

ERC721Storage

storage-location: erc8042:erc721

Definition
struct ERC721Storage {
mapping(uint256 tokenId => address owner) ownerOf;
mapping(address owner => uint256 balance) balanceOf;
mapping(address owner => mapping(address operator => bool approved)) isApprovedForAll;
mapping(uint256 tokenId => address approved) approved;
}

State Variables

PropertyTypeDescription
STORAGE_POSITIONbytes32Diamond storage slot position for this module (Value: keccak256("erc721.enumerable"))
ERC721_STORAGE_POSITIONbytes32Diamond storage slot position for this module (Value: keccak256("erc721"))

Functions

burn

Burns (destroys) a token, removing it from enumeration tracking. This module does not check for approval. Use the facet for approval-checked burns.

function burn(uint256 _tokenId) ;

Parameters:

PropertyTypeDescription
_tokenIduint256The ID of the token to burn.

getERC721Storage

Returns a pointer to the ERC-721 storage struct. Uses inline assembly to access the storage slot defined by STORAGE_POSITION.

function getERC721Storage() pure returns (ERC721Storage storage s);

Returns:

PropertyTypeDescription
sERC721StorageThe ERC721Storage struct in storage.

getStorage

Returns the storage struct used by this facet.

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

Returns:

PropertyTypeDescription
sERC721EnumerableStorageThe ERC721Enumerable storage struct.

Events

Errors

Best Practices

Best Practice
  • Call burn only after verifying token ownership and necessary approvals within the calling facet.
  • Ensure the calling facet correctly handles the Transfer event emitted by this module.
  • Verify that the diamond's storage layout is compatible when upgrading facets that interact with this module.

Integration Notes

Shared Storage

This module interacts with diamond storage at the STORAGE_POSITION defined by keccak256("erc721.enumerable"). The burn function modifies the ERC721EnumerableStorage struct, ensuring that burned tokens are no longer tracked in enumeration. Changes to this shared storage are immediately visible to all facets operating within the same diamond.

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.