ERC-20 (Fungible Tokens)

The ERC-20 standard defines a set of functions and events that a token contract on the Ethereum blockchain should implement. ERC-20 tokens are fungible, meaning each token is identical and can be exchanged one-to-one.

ERC-20 defines several key functions, including:

Supported

name

function name() public view returns (string)

Returns the name of the token.

symbol

function symbol() public view returns (string)

Returns the symbol of the token.

decimals

function decimals() public view returns (uint8)

Returns the number of decimals the token uses.

totalSupply

function totalSupply() external view returns (uint256)

Returns the total supply of the token.

balanceOf

function balanceOf(address account) external view returns (uint256)

Returns of the balance of the token in the specified account. The account is the Hedera account ID 0.0.x in Solidity address format or the evm address of a contract that has been created via the CREATE2 operation.

transfer

function transfer(address recipient, uint256 amount) external returns (bool)

Transfer tokens from your account to a recipient account. The recipient is the Hedera account ID 0.0.x in Solidity format or the evm address of a contract that has been created via CREATE2 operation.

allowance

function allowance(address owner, address spender) external view returns (uint256)

Returns the remaining number of tokens that spender will be allowed to spend on behalf of owner through transferFrom. This is zero by default. This value changes when approve or transferFrom are called. This works by loading the owner FUNGIBLE_TOKEN_ALLOWANCES from the accounts ledger and returning the allowance approved for spender The owner and spender address are the account IDs (0.0.num) in solidity format.

approve

function approve(address spender, uint256 amount) external returns (bool)

Sets amount as the allowance of spender over the caller's tokens.

This works by creating a synthetic CryptoApproveAllowanceTransaction with payer - the account that called the precompile (the message sender property of the message frame in the EVM).

Fires an approval event with the following signature when executed: event Approval(address indexed owner, address indexed spender, uint256 value);

transferFrom

function transferFrom(address sender, address recipient, uint256 amount) external returns (bool)

Moves amount tokens from from to to using the allowance mechanism. amount is then deducted from the caller's allowance.

This works by creating a synthetic CryptoTransferTransaction with fungible token transfers with the is_approval property set to true.


Additional References

Last updated