What's a token?

  • Blockchains have a native coin/token that the chain is built with. These coins/tokens are required to execute transactions, send data, are rewards for mining, etc.
  • But it may be possible to encode additional metadata in the chain which represents a token.
  • Depending on the chain, this can be easy or hard.

Why use tokens?

  • Say you want to issue share of stocks to the many co-founders (different percentages) for your new startup company that is yet to be registered
  • In the Ethereum world, you can represent the shares in the form of “tokens” that can be sold, sold back to the company, transferred, etc.
  • You can create a “token contract” and deploy it in Ethereum blockchain
    • Then the tokens can be transferred, sold, etc.

ERC-20 standard

ERC-20 tokens

  • ERC20 is a “token standard” for creating Ethereum token contracts
  • ERC stands for Ethereum Request for Comments
  • Any token contract that adheres to the specification follows ERC20
  • Can use with any wallets that understand ERC20
  • Most ICOs (Initial Coin Offerings) have adhered to ERC20

ERC-20 Interface


      interface IERC20 {
          function name() public view returns (string memory);
          function symbol() public view returns (string memory);
          function decimals() public view returns (uint8);
          function totalSupply() external view returns (uint256);
          function balanceOf(address owner) external view returns (uint256 balance);
          function transfer(address recipient, uint256 amount) external returns (bool success);
          function transferFrom(address sender, address recipient, uint256 amount) external returns (bool success);
          function approve(address spender, uint256 amount) external returns (bool success);
          function allowance(address owner, address spender) external view returns (uint256 remaining);
          event Transfer(address indexed sender, address indexed recipient, uint256 amount);
          event Approval(address indexed owner, address indexed spender, uint256 amount);
      }
  

ERC20 Mandatory functions

ERC20 Events

Events are only accessible by off-chain application; contracts do not have access to events

Demo : Standard ERC20 Token Contract

ERC20 ICO

DEMO : Initial Coin Offering using ERC20

Examples of ERC-20 Tokens

https://etherscan.io/tokens

Recommended Resources