Skip to main content

ERC-721 Burn Module

Burns ERC-721 tokens using diamond storage

Key Features
  • Provides internal functions for token burning.
  • Utilizes the diamond storage pattern for shared state.
  • No external dependencies, ensuring minimal on-chain footprint.
  • Emits Transfer event upon successful token burning.
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 internal functions for burning ERC-721 tokens. Facets can import and use this module to remove tokens from circulation via shared diamond storage. Token state changes made through this module are immediately visible to all facets accessing the same storage.

Storage

ERC721Storage

Storage layout for ERC-721 token management. Defines ownership, balances, approvals, and operator mappings per ERC-721 standard. 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"))

Functions

burn

Burns (destroys) a specific ERC-721 token. Reverts if the token does not exist. Clears ownership and approval. This module does not perform approval checks. Ensure proper ownership or approval validation before calling this function.

function burn(uint256 _tokenId) ;

Parameters:

PropertyTypeDescription
_tokenIduint256The ID of the token to burn.

getStorage

Returns the ERC-721 storage struct from its predefined slot. Uses inline assembly to access diamond storage location.

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

Returns:

PropertyTypeDescription
sERC721StorageThe storage reference for ERC-721 state variables.

Events

Errors

Best Practices

Best Practice
  • Ensure appropriate ownership or approval checks are performed by the calling facet before invoking burn.
  • Verify that the ERC721Storage struct definition used by this module is compatible with your diamond's storage layout.
  • Handle the ERC721NonexistentToken error if the token ID provided to burn does not exist.

Integration Notes

Shared Storage

This module interacts with diamond storage at the STORAGE_POSITION defined by keccak256(\"erc721\"). The burn function modifies internal state within the ERC721Storage struct, including clearing ownership and approvals for the specified token ID. The getStorage function provides direct access to this shared storage struct via inline assembly. Changes to this storage are immediately visible to all facets 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.