Skip to main content

ERC-20 Metadata Module

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

Helper functions for writing token metadata and accessing metadata storage

Key Features
  • setMetadata writes the name, symbol, and decimals in one call.
  • No access control is performed. Use it from trusted initialization code only.
  • Emits no event, so metadata changes leave no log for off-chain indexers.
Module Usage

Use helper functions from Compose using your own custom facets. See Facets & Modules for more information.

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

getStorage

Returns a pointer to the ERC20MetadataStorage struct.

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

Returns:

PropertyTypeDescriptionsERC20MetadataStorage storageThe struct in storage.

setMetadata

Writes the token name, symbol, and decimals.

All three fields are overwritten on every call. There is no way to update one field and leave the others untouched, so pass the current values for the fields you are not changing, or write through getStorage instead.

There is no msg.sender or role check. Use only from trusted initialization code, or wrap it with your own checks in a facet.

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

Parameters:

PropertyTypeDescription_namestringThe descriptive name of the token, for example "My Token"._symbolstringThe short ticker of the token, for example "MTK"._decimalsuint8Decimal places used when displaying balances. 18 is the usual choice.

Best Practices

Integration Notes

Import the module under a namespace and call it from your diamond constructor:

Setting metadata during deployment
import "src/token/ERC20/Metadata/ERC20MetadataMod.sol" as ERC20MetadataMod;

contract MyDiamond {
constructor() {
ERC20MetadataMod.setMetadata("My Token", "MTK", 18);
}
}

ExampleDiamond wires the ERC-721 equivalent the same way, calling ERC721MetadataMod.setMetadata from its constructor.

ERC20MetadataStorage lives at keccak256("erc20.metadata"), which is a separate slot from the erc20 slot holding balances and allowances. Adding or removing metadata contracts never touches balances.

ERC20PermitFacet reads name from this same slot to build its EIP-712 domain. Changing the name after deployment invalidates permit signatures that have already been issued but not yet used.

Last updated:

Newsletter

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

No spam. Unsubscribe anytime.