Skip to main content

ERC-721 Enumerable Burn Facet

ERC-721 token burning and enumeration tracking

Key Features
  • Implements ERC-721 token burning.
  • Integrates with diamond storage for enumeration tracking.
  • Exposes burn function externally via the diamond proxy.
  • Provides internal functions (getStorage, getERC721Storage) for accessing facet-specific and shared storage.

Overview

This facet implements ERC-721 token burning functionality within a Compose diamond. It exposes external functions for destroying tokens and integrates with diamond storage for enumeration tracking. Developers add this facet to manage token lifecycle and maintain correct token counts.

Storage

ERC721EnumerableStorage

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

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.

function burn(uint256 _tokenId) external;

Parameters:

PropertyTypeDescription
_tokenIduint256The ID of the token to burn.

exportSelectors

Exports the function selectors of the ERC721EnumerableBurnFacet 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 ERC721EnumerableBurnFacet

Events

Errors

Best Practices

Best Practice
  • Ensure the ERC721EnumerableBurnFacet is properly registered with the diamond proxy.
  • Initialize the diamond's storage for ERC-721 before adding this facet.
  • Verify that the burn function's access control is configured appropriately for your diamond's security model.

Security Considerations

Security

The burn function is an external function and should have appropriate access controls implemented at the diamond level to prevent unauthorized token destruction. The function removes a token from enumeration tracking, which could affect other facets relying on token order or count. Errors ERC721NonexistentToken and ERC721InsufficientApproval are emitted if the token does not exist or if approval conditions are not met, respectively.

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.