Skip to main content

ERC721EnumerableBurnFacet

Burns ERC-721 tokens and removes them from enumeration

Key Features
  • Exposes external function burn(uint256 tokenId) for token destruction.
  • Integrates with ERC-721 enumeration tracking.
  • Follows EIP-2535 diamond standard for composability.
  • Uses internal getStorage() for state access.

Overview

This facet provides functionality to burn ERC-721 tokens within a diamond proxy, ensuring they are removed from enumeration tracking. It exposes the burn function for token destruction and getStorage for internal access to its state. Integrate this facet to enable token destruction capabilities while maintaining the diamond's upgradeability and composition.


Storage

ERC721EnumerableStorage

Definition
struct ERC721EnumerableStorage {
mapping(uint256 tokenId => address owner) ownerOf;
mapping(address owner => uint256[] ownerTokens) ownerTokens;
mapping(uint256 tokenId => uint256 ownerTokensIndex) ownerTokensIndex;
uint256[] allTokens;
mapping(uint256 tokenId => uint256 allTokensIndex) allTokensIndex;
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("compose.erc721.enumerable"))

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.

Events

Errors

Best Practices

Best Practice
  • Initialize the facet's storage during diamond setup.
  • Ensure the caller has the necessary permissions to burn the specified token.
  • Verify that the token exists before attempting to burn it.

Security Considerations

Security

The burn function should be protected by appropriate access control mechanisms to prevent unauthorized token destruction. Input validation for _tokenId is crucial to prevent issues with non-existent tokens, which will revert with ERC721NonexistentToken. Ensure that the caller has sufficient approval to burn the token, otherwise ERC721InsufficientApproval will be reverted.

Was this helpful?
Last updated: