Skip to main content

ERC-20 Data Facet

ERC-20 token data retrieval within a diamond

Key Features
  • 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

Definition
struct ERC20Storage {
mapping(address owner => uint256 balance) balanceOf;
uint256 totalSupply;
mapping(address owner => mapping(address spender => uint256 allowance)) allowance;
}

State Variables

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

Functions

totalSupply

Returns the total supply of tokens.

function totalSupply() external view returns (uint256);

Returns:

PropertyTypeDescription
-uint256The total token supply.

balanceOf

Returns the balance of a specific account.

function balanceOf(address _account) external view returns (uint256);

Parameters:

PropertyTypeDescription
_accountaddressThe address of the account.

Returns:

PropertyTypeDescription
-uint256The account balance.

allowance

Returns the remaining number of tokens that a spender is allowed to spend on behalf of an owner.

function allowance(address _owner, address _spender) external view returns (uint256);

Parameters:

PropertyTypeDescription
_owneraddressThe address of the token owner.
_spenderaddressThe address of the spender.

Returns:

PropertyTypeDescription
-uint256The remaining allowance.

exportSelectors

Exports the function selectors of the ERC20Data facet This function is use as a selector discovery mechanism for diamonds

function exportSelectors() external pure returns (bytes memory);

Returns:

PropertyTypeDescription
-bytesselectors The exported function selectors of the ERC20DataFacet

Best Practices

Best Practice
  • Ensure the ERC20DataFacet is added to the diamond and its selectors are registered.
  • Access token data by calling functions through the diamond proxy address.
  • Use the exportSelectors function during diamond deployment or upgrade to discover facet selectors.

Security Considerations

Security

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.

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.