ERC-20 Metadata Module
Manage ERC-20 token metadata within a diamond
- 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.
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
State Variables
| Property | Type | Description |
|---|---|---|
STORAGE_POSITION | bytes32 | Diamond 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.
Returns:
| Property | Type | Description |
|---|---|---|
s | ERC20MetadataStorage | The ERC20 storage struct reference. |
setMetadata
Sets the metadata for the ERC20 token.
Parameters:
| Property | Type | Description |
|---|---|---|
_name | string | The name of the token. |
_symbol | string | The symbol of the token. |
_decimals | uint8 | The number of decimals used for token precision. |
Best Practices
- Ensure the
ERC20MetadataModis correctly initialized with the diamond's storage pointer before callingsetMetadata. - Call
setMetadataonly once during the diamond's initialization phase to establish token identity. - Verify that the
STORAGE_POSITIONandkeccak256("erc20.metadata")key are correctly configured for the diamond's storage mapping.
Integration Notes
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.