📌 Tokens on Ethereum

Blockchain tokens existed before Ethereum. In some ways, the first blockchain currency, Bitcoin, is a token itself. Many token platforms were also developed on Bitcoin and other cryptocurrencies before Ethereum. However, the introduction of the first token standard on Ethereum let to an explosion of tokens.

Tokens are different from ether because the Ethereum protocol does not know anything about them. Sending ether is an intrinsic action of the Ethereum platform, but sending or even owning tokens is not. The ether balance of Ethereum accounts is handled at the protocol level, whereas the token balance of Ethereum accounts is handled at the smart contract level. In order to create a new token on Ethereum, you must create a new smart contract. Once deploy, the smart contract handles everything, including ownership, transfers, and access rights. You can write your smart contract to perform all the necessary actions any way you want, but it is probably wisest to follow an existing standard.

📌 ERC-20 Token Standard

The first standard was introduced in November 2015 by Fabian Vogelsteller as an Ethereum Request for Comments (ERC). The vast majority of tokens are currently based on the ERC-20 standard. The ERC-20 request for comments eventually became Ethereum Improvement Proposal 20 (EIP-20), but it is mostly still referred to by the original name, ERC-20.

ERC-20 is a standard for fungible tokens, meaning that different units of an ERC-20 token are interchangeable and have no unique properties.

The ERC-20 standard defines a common interface for contracts implementing a token, such that any compatible token can be accessed and used in the same way. The interface consists of a number of functions that must be present is every implementation of the standard, as well as some optional functions and attributes that may be added by developers.

🎯 ERC-20 required functions and events

An ERC-20 compliant token contract must provide at least the following functions and events:

  1. totalSupply

    Returns the total units of this token that currently exist. ERC-20 tokens can have a fixed or a variable supply.

  2. balanceOf

    Given an address, returns the token balance of that address.

  3. transfer

    Given an address and amount, transfers that amount of tokens to that address, from the balance of the address that executed the transfer.

  4. transferFrom

    Given a sender, recipient, and amount, transfers tokens from one account to another. Used in combination with approve.