Skip to main content

ERC-20 Metadata Module

Manage ERC-20 token metadata within a diamond

Key Features
  • Internal functions for setting and retrieving metadata.
  • Utilizes the diamond storage pattern (EIP-8042) for shared state.
  • No external dependencies, promoting composability.
  • Directly manipulates storage slots for metadata.
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 to set and retrieve ERC-20 token metadata, such as name, symbol, and decimals. Facets can import this module to manage token metadata using shared diamond storage, ensuring consistency across all facets interacting with the token.

Storage

ERC20MetadataStorage

ERC-8042 compliant storage struct for ERC20 token data. storage-location: erc8042:erc20.metadata

Definition
struct ERC20MetadataStorage {
string name;
string symbol;
uint8 decimals;
}

State Variables

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

Functions

getStorage

Returns the ERC20 storage struct from the predefined diamond storage slot. Uses inline assembly to set the storage slot reference.

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

Returns:

PropertyTypeDescription
sERC20MetadataStorageThe ERC20 storage struct reference.

setMetadata

Sets the metadata for the ERC20 token.

function setMetadata(string memory _name, string memory _symbol, uint8 _decimals) ;

Parameters:

PropertyTypeDescription
_namestringThe name of the token.
_symbolstringThe symbol of the token.
_decimalsuint8The number of decimals used for token precision.

Best Practices

Best Practice
  • Ensure the ERC20MetadataMod is correctly initialized with the diamond's storage pointer before calling setMetadata.
  • Call setMetadata only once during the diamond's initialization phase to establish token identity.
  • Verify that the STORAGE_POSITION and keccak256("erc20.metadata") key are correctly configured for the diamond's storage mapping.

Integration Notes

Shared Storage

This module interacts with diamond storage at a specific STORAGE_POSITION identified by keccak256("erc20.metadata"). The ERC20MetadataStorage struct, containing name, symbol, and decimals, is stored at this location. All facets that import and use this module will access and modify the same shared storage, ensuring metadata consistency across the diamond. Changes made by setMetadata are immediately visible to any facet calling getStorage.

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.