Skip to main content

ERC-20 Burn Module

Internal ERC-20 token burning functionality

Key Features
  • Exposes only internal functions, intended for use within custom facets.
  • Operates on shared diamond storage using EIP-8042 semantics.
  • Emits Transfer events upon successful burning, signaling changes in token ownership.
  • Reverts with custom errors ERC20InsufficientBalance and ERC20InvalidSender for explicit error handling.
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-20 tokens, reducing the total supply and an account's balance. Facets can import this module to implement burning logic, operating on shared diamond storage. Changes to token supply and balances are immediately visible to all facets interacting with the same storage.

Storage

ERC20Storage

ERC-20 storage layout using the ERC-8042 standard. storage-location: erc8042:erc20

Definition
struct ERC20Storage {
mapping(address owner => uint256 balance) balanceOf;
uint256 totalSupply;
}

State Variables

PropertyTypeDescription
STORAGE_POSITIONbytes32Diamond storage slot position for this module (Value: keccak256("erc20"))

Functions

burn

Burns tokens from a specified address. Decreases both total supply and the sender's balance. This module does not perform allowance checks. Ensure proper allowance or authorization validation before calling this function.

function burn(address _account, uint256 _value) ;

Parameters:

PropertyTypeDescription
_accountaddressThe address whose tokens will be burned.
_valueuint256The number of tokens to burn.

getStorage

Returns a pointer to the ERC-20 storage struct. Uses inline assembly to bind the storage struct to the fixed storage position.

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

Returns:

PropertyTypeDescription
sERC20StorageThe ERC-20 storage struct.

Events

Errors

Best Practices

Best Practice
  • Ensure _account authorization and allowance checks are performed before calling burn functions to prevent unauthorized burning.
  • Handle ERC20InsufficientBalance and ERC20InvalidSender errors to gracefully manage invalid operations.
  • Verify that the storage pointer is correctly initialized and points to the shared diamond storage slot designated for ERC-20 data.

Integration Notes

Shared Storage

This module interacts with diamond storage at the STORAGE_POSITION slot, identified by keccak256("erc20"). The getStorage function returns a pointer to the ERC20Storage struct, which contains the totalSupply variable. The burn function directly modifies the totalSupply and the balance of the specified _account within this shared storage. Any facet that reads from or writes to this same storage slot will immediately observe these changes.

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.