Understanding ERC-20 Tokens
In 2015 the Ethereum blockchain-based platform was launched and the concept of blockchain evolves into a second generation category driven by the requirement of general purpose application. This platform is not a simple cryptocurrency but it is a digital environment that can be used for decentralized projects.
The most remarkable innovation of Ethereum is the enablement of smart contracts. They allow for binding agreements between network participants that are handled by network consensus instead of a third party and provide security to transactions, verifying the execution of all conditions by all the peers and processing the transaction as the result of this execution.
The ability of the Ethereum Blockchain to store not only ownership – similarly to the Bitcoin blockchain – but also execution code in the form of smart contracts has led to the creation of an immense number of new types of tokens based on the Ethereum ERC-20 protocol. Tokens, in this regard, are a representation of an asset, right, ownership, access, cryptocurrency, or anything else that is not unique in and of itself but can be transferred.
The number of the ERC-20 token contracts has experienced an exponential growth since 2015. In 2018, there were around 40,000 ERC-20 contracts on the Ethereum network and, at the time of writing, Token Tracker claims that they are more than 720,000.
What is ERC-20?
Ethereum’s ERC-20 (representing Ethereum Request for Comment) is the most widely used token standard that implements an API for tokens within smart contracts. It is used on Ethereum blockchain for token implementation and provides several rule that Ethereum-based tokens must respect. The goal and need for ERC-20 tokens is to share a common set of standards, to create interoperability and compatibility between tokens and to foster improvements in the Ethereum ecosystem.
In the Ethereum blockchain platform, Ethereum Request for Comments (ERC) is a document that smart contract programmers use to write smart contracts. In these documents, Ethereum-based tokens are described as having to comply with certain rules.
The ERC-20 standard was proposed in late 2015 by Fabian Vogelsteller and Vitalik Buterin to establish a common interface for creating and issuing new tokens on the network. ERC-20 significantly reduces the effort needed to create and issue a digital token by allowing different smart-contract enabled tokens a way to be exchanged. Crucially, the ERC-20 standard allows frictionless interoperability, so that any compliant Ethereum wallet software can transact and monitor the full range of compliant tokens.
The protocol defines technical specifications giving developers the ability to program how new tokens will function within the Ethereum ecosystem. In particular – according to the summary provided by the authors – it provides basic functionality to transfer tokens, as well as allow tokens to be approved so they can be spent by another on-chain third party. Compliance to the standard avoids confusion and enables tokens to interact with wallets, exchanges and different smart contracts smoothly without running into issues due to individual token differences. In this way, ERC-20 allows any Ethereum wallet to control a diverse portfolio of token investments.
ERC-20 standard effectively allows smart contracts to act very similarly to a conventional cryptocurrency like Bitcoin, or Ethereum itself. A token hosted on the Ethereum blockchain can be sent, received, checked of its total supply, and checked for the amount that is available on an individual address. To allow this, ERC-20 standard draws up a set of six different mandatory functions that a smart contract should implement to emulate a digital token:
- totalSupply – this function enables an instance of the contract to calculate and return the amount of the token that exists in circulation;
- balanceOf – this function returns the token balance of the given address;
- transfer – this function enables the owner of the contract to send a certain amount of token to another address, just like a conventional cryptocurrency transaction.
- transferFrom – this function allow to transfer the token from a wallet to a smart contract or viceversa, defining where the tokens are transfering from. Unlike transfer, it allows a smart contract to automate the transfer process and send a given amount of the token on behalf of the owner;
- approve – the owner calling this function authorizes (or approves) a smart contract or another address to withdraw funds from the address sending the transaction. This is an implicit field provided by external applications such as wallets so that they can better interact with the contract;
- allowance – this function checks if one user has enough balance to send a certain amount of tokens to another.
The optional functions, instead, are:
- name – This function returns the name of the token;
- symbol – This function returns the symbol of the token;
- decimals – This function is used to specify how many decimal places a token has, effectively shifting all numbers by the declared number of zeros to simulate decimals. The most common number of decimals to consider is 18.
In addition, there are two specific defined events:
- Approval – This function allows applications to reconstruct the allowance for all accounts just by listening to said events.
- Transfer - that can be invoked or emitted when a user is granted rights to withdraw tokens from an account, and then the tokens are actually transferred.
In combination, all these functions cover the entire behavior of a token that can be used as a currency.
Difference between standard coins and ERC-20 tokens
ERC-20 and other token standards are widely used by many digital currencies such as Basic Attention Token, OmiseGO or Augur. What sets ERC-20 tokens apart from standard cryptocurrency is that cryptocurrencies are the native asset of a blockchain (like BTC, RBTC, or ETH) whereas tokens are built on an existing blockchain using smart contracts. ERC-20 tokens, in particular, are created and hosted on the Ethereum blockchain, where ETH network fees are required to carry out crypto transactions.
Other ERC Standards and implementations
In addition to the ERC-20 standards, there are several other token standards.
According to the official documentation, an ERC-20 token contract is designed to be used as a fungible token, meaning each unit is exactly equal to any other token; no tokens have special rights or behavior associated with them, which means that no token is unique. This makes ERC-20 tokens useful for things like a medium of exchange currency, voting rights, staking, and more.
Another popular token standard is the ERC-721, which is the NFT standard. Unlike ERC-20, it establish ownership of unique digital or real-world assets, which then makes them “non-fungible”. Each ERC-721 token is unique and distinguishable, can be traded, bought, and sold just like ERC-20 tokens, but aren't interchangeable. This feature can be used to tokenize everything from art to an individual’s identity.
Others standards – such as the ERC-677, ERC-827, ERC-223 or the ERC-1155 – are designed to enhance the functionality of the main standards, improve their functioning or allowing other specific implementations. Each of these token standards has its own advantages and disadvantages and is designed to serve a different purpose.
- ERC-20 Token Standard on ethereum.org
- ERC20 Transactions over Ethereum Blockchain: Network Analysis and Predictions, available here.
- Ethereum Smart Contracts Optimization, available here.
- ERC-20 - OpenZeppelin Docs
- What is an ERC-20 token?, available here.
- McKie, S. (2020, May 5). The Anatomy of ERC20 – BlockChannel
- Phuture Finance. (n.d.). Tokens, standards, and smart contracts: The differences between ERC-20 and ERC-721 - Phuture