ERC-20 tokens

ERC-20 tokens are a type of fungible token standard in the Ethereum ecosystem. They are essentially smart contracts that define a set of rules for creating and transferring tokens on the Ethereum blockchain. ERC-20 tokens are designed to be interoperable and easily exchangeable with other ERC-20 tokens, as they share a common set of functions and events.

ERC-20 tokens can be used to represent anything of value, such as a currency, a commodity, a share in a company, or even a tokenized asset. They allow for the creation of decentralized applications (DApps) that can use a common token for a variety of purposes.

ERC-20 tokens have a set of standard functions, such as totalSupply, balanceOf, transfer, approve, and allowance, among others. These functions allow for the creation and transfer of tokens, as well as the management of token allowances for other addresses.

ERC-20 tokens have become a widely adopted standard in the Ethereum ecosystem, and are used in a wide range of applications such as cryptocurrency exchanges, decentralized finance (DeFi) platforms, and more.

ERC-20 tokens are useful for creating fungible tokens on the Ethereum network. They are commonly used for creating digital assets that can be traded on decentralized exchanges, used as a form of payment, or as a representation of some underlying asset or currency. Examples of ERC-20 tokens include stablecoins, utility tokens, security tokens, and more. The ERC-20 standard provides a widely recognized set of rules that allows these tokens to be easily integrated into other applications and services, increasing their utility and value.

Example Interface

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

interface IERC20 {
    function totalSupply() external view returns (uint256);

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

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

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

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

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

    //OPTIONAL
    function name() external view returns (string memory);
    
    //OPTIONAL
    function symbol() external view returns (string memory);
    
    //OPTIONAL
    function decimals() external view returns (uint8);
    
    event Transfer(address indexed from, address indexed to, uint256 value);

    event Approval(address indexed owner, address indexed spender, uint256 value);
}

This interface defines the basic functions and events that an ERC-20 token must implement. It includes functions for getting the total supply of the token, checking an account's balance, transferring tokens, approving an allowance for another account, and transferring tokens from one account to another. The interface also includes events for when a transfer or approval occurs.

name, symbol, and decimals are properties defined in the ERC-20 standard that provide basic information about the token.

name: The name of the token. For example, "My Token".

symbol: The symbol of the token. For example, "MYT".

decimals: The number of decimal places that the token uses. For example, if the token uses 18 decimal places, then the smallest unit of the token is 0.000000000000000001.

These properties can be used to help users easily identify and recognize the token, and to enable wallets and other tools to properly display and handle the token's values.

Additional Resources

Last updated