Skip to main content

ERC-20 Metadata Facet

@perfect-abstractions/compose/token/ERC20/Metadata/ERC20MetadataFacet.sol

Read-only access to the token name, symbol, and decimals

Key Features
  • Exposes the three ERC-20 metadata view functions: name(), symbol() and decimals().
  • Uses ERC20MetadataStorage at erc8042:erc20.metadata, a different slot from balances and allowances.
  • Read-only facet. Values are written by ERC20MetadataMod.

Storage

State Variables

PropertyTypeDescriptionSTORAGE_POSITIONbytes32ERC-20 metadata storage position within the diamond (Value: keccak256("erc20.metadata"))

ERC20MetadataStorage

Definition
/** @custom:storage-location erc8042:erc20.metadata */
struct ERC20MetadataStorage {
string name;
string symbol;
uint8 decimals;
}

Functions

name

Returns the descriptive name of the token, for example "My Token".

function name() external view returns (string memory);

Returns:

PropertyTypeDescription-stringThe token name, or an empty string if metadata was never set.

symbol

Returns the short ticker of the token, for example "MTK".

function symbol() external view returns (string memory);

Returns:

PropertyTypeDescription-stringThe token symbol, or an empty string if metadata was never set.

decimals

Returns how many decimal places wallets and interfaces should use when displaying balances.

function decimals() external view returns (uint8);

Returns:

PropertyTypeDescription-uint8The number of decimals, or 0 if metadata was never set. 18 is the usual choice.

Best Practices

Security Considerations

This facet only reads storage, so it cannot corrupt token state on its own. Two consequences of the shared slot are worth knowing:

Last updated:

Newsletter

Get notified about releases, feature announcements, and technical deep-dives on building smart contracts with Compose.

No spam. Unsubscribe anytime.