Skip to main content

ERC-20 Data Facet

@perfect-abstractions/compose/token/ERC20/Data/ERC20DataFacet.sol

Read-only ERC-20 token data access for diamonds

Key Features
  • Exposes the three ERC-20 view functions: totalSupply(), balanceOf() and allowance().
  • Shares ERC20Storage at erc8042:erc20 with every other ERC-20 facet and module.
  • Read-only facet. It never writes to storage.

Storage

State Variables

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

ERC20Storage

Definition
/** storage-location: erc8042:erc20 */
struct ERC20Storage {
mapping(address owner => uint256 balance) balanceOf;
uint256 totalSupply;
mapping(address owner => mapping(address spender => uint256 allowance)) allowance;
}

Functions

totalSupply

Returns the total number of tokens in circulation.

function totalSupply() external view returns (uint256);

Returns:

PropertyTypeDescription-uint256The total token supply, or 0 if no tokens have been minted.

balanceOf

Returns the token balance held by an account.

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

Parameters:

PropertyTypeDescription_accountaddressThe address to query. Unknown addresses are not an error, they simply return 0.

Returns:

PropertyTypeDescription-uint256The number of tokens held by _account.

allowance

Returns how many tokens a spender may still move on an owner's behalf.

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

Parameters:

PropertyTypeDescription_owneraddressThe address that owns the tokens and granted the allowance._spenderaddressThe address permitted to spend on the owner's behalf.

Returns:

PropertyTypeDescription-uint256The remaining allowance. A value of type(uint256).max is treated as unlimited and is never decremented on transfer.

Best Practices

Security Considerations

This facet only reads storage, so it cannot corrupt token state on its own. Two things are still 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.