ERC-20 Data Facet
ERC-20 token data retrieval within a diamond
- Exposes external view functions for ERC-20 data retrieval.
- Reads data directly from shared diamond storage.
- No state-changing functions, ensuring read-only operations.
- Compatible with ERC-2535 diamond standard for seamless integration.
Overview
This facet provides external view functions for retrieving ERC-20 token data, such as total supply, account balances, and allowances. It interacts with shared diamond storage to access this information, ensuring consistency across all facets. Developers integrate this facet to expose token metrics externally while maintaining the diamond's upgradeability.
Storage
ERC20Storage
State Variables
| Property | Type | Description |
|---|---|---|
STORAGE_POSITION | bytes32 | Diamond storage slot position for this module (Value: keccak256("erc20")) |
Functions
totalSupply
Returns the total supply of tokens.
Returns:
| Property | Type | Description |
|---|---|---|
- | uint256 | The total token supply. |
balanceOf
Returns the balance of a specific account.
Parameters:
| Property | Type | Description |
|---|---|---|
_account | address | The address of the account. |
Returns:
| Property | Type | Description |
|---|---|---|
- | uint256 | The account balance. |
allowance
Returns the remaining number of tokens that a spender is allowed to spend on behalf of an owner.
Parameters:
| Property | Type | Description |
|---|---|---|
_owner | address | The address of the token owner. |
_spender | address | The address of the spender. |
Returns:
| Property | Type | Description |
|---|---|---|
- | uint256 | The remaining allowance. |
exportSelectors
Exports the function selectors of the ERC20Data facet This function is use as a selector discovery mechanism for diamonds
Returns:
| Property | Type | Description |
|---|---|---|
- | bytes | selectors The exported function selectors of the ERC20DataFacet |
Best Practices
- Ensure the
ERC20DataFacetis added to the diamond and its selectors are registered. - Access token data by calling functions through the diamond proxy address.
- Use the
exportSelectorsfunction during diamond deployment or upgrade to discover facet selectors.
Security Considerations
This facet contains only view functions and does not modify state. Standard Solidity security practices should be followed when interacting with the diamond proxy. Input validation is handled by the underlying diamond proxy mechanism for external calls.