ERC20 Token Standard

The ERC20 token standard provides a standardized way to implement fungible (interchangeable) tokens on the Ethereum blockchain. Standardizing tokens allows developers to program applications to interact with new tokens automatically without having to customize for each token contract.

ERC20 Interface

The ERC20 standard defines a common interface that all Ethereum tokens should adhere to. This interface includes six required functions:

totalSupply()

Returns the total token supply. This value is not expected to change often.

function totalSupply() public view returns (uint256);

balanceOf(account)

Returns the account balance of the account with address account.

function balanceOf(address account) public view returns (uint256);

transfer(to, amount)

Transfers amount tokens from msg.sender to the address to. This should fire the Transfer event.

function transfer(address to, uint256 amount) public returns (bool);

approve(spender, amount)

Sets amount as the allowance for spender to withdraw from msg.sender. This should fire the Approval event.

function approve(address spender, uint256 amount) public returns (bool);

allowance(owner, spender)

Returns the amount spender is still allowed to withdraw from owner.

function allowance(address owner, address spender) public view returns (uint256);

transferFrom(from, to, amount)

Transfers amount tokens from address from to address to. The calling address must have allowance to transfer from from account.

function transferFrom(address from, address to, uint256 amount) public returns (bool);

Events

ERC20 tokens should also emit events for successful transfers and approvals:

event Transfer(address indexed from, address indexed to, uint256 value); event Approval(address indexed owner, address indexed spender, uint256 value);

These events are used off-chain to track token transactions.

Implementing ERC20 Tokens

Developers can either create a token contract from scratch that follows the ERC20 interface or use a standard implementation such as OpenZeppelin’s ERC20 contract.

Tools like OpenZepplin SDK and Token Factory also simplify deployment.

Benefits

The main benefits of adhering tokens to the ERC20 standard include:

  • Interoperability – ERC20 tokens work seamlessly with external apps and services designed for these tokens like exchanges and wallets.
  • Fungibility – Each token unit is interchangeable, allowing easy valuation and liquidity.
  • Transparency – The required events provide transparency into transactions, balances, and allowances.

Nearly all initial coin offerings launched on Ethereum are ERC20 compliant. Leading examples include USDC, UNI, LINK, COMP, MKR, and AAVE.

Scroll to Top