What are ERC20 Tokens?
DApps or Decentralised Apps that run on Ethereum use tokens which can function as currency or share in a company or right to buy products of the company or loyalty points.
In the past, every DApp developer who coded a new token, she had to do it from scratch leading to several practical problems:
DApp development would take more time as she'd simply be re-inventing the wheel.
There were more opportunities for mistakes and bugs which a hacker could exploit.
The tokens following different standards wouldn’t be easily interchangeable
An Exchange and Wallet would have to create customized code to list every new token.
Clearly, there was a need for a standard that all developers could follow when creating tokens for their DApps.
Presenting - ERC20.
ERC stands for Ethereum Request for Comments. 20 is simply the proposal identifier. It has played a key role in developing the ICO industry and making cryptocurrencies more mainstream
ERC20 is still not perfect but solves the 4 practical issues mentioned above. In the time it has been around, it has been constantly peer-reviewed and is less prone to bugs than a new code might be. The standard defines rules that apply to all ERC-20 tokens and allows them to interact seamlessly with each other. Exchanges can now add new tokens quite quickly and any wallet that accepts Ether tends to accept all ERC-20 tokens.
Let’s talk technicals.
ERC-20 is the technical standard used for smart contracts on the Ethereum blockchain for token implementation. It is a common list of rules that Ethereum tokens must adhere to.
ERC-20 defines 3 optional and 6 mandatory functions for smart contracts:
the 3 optional functions are
Token Name- Eg: Crypto Block
Symbol - Eg: CRB
Decimal Places - Decide how divisible the token is by specifying how many decimal spaces it should support (maximum allowed is 18)
The mandatory functions are:
[totalSupply]- Defines the Total Supply of your tokens. Once the limit is reached, no new tokens will be created.
[balanceOf]- Returns how many tokens a given address has.
[transfer]- Used to take tokens from total token supply and gives it to a user.
[transferFrom]- allows transfer of tokens between any 2 users.
[approve]- checks transaction against total supply of tokens. This ensures that there are no counterfeit tokens.
[allowance]- check if a particular user has enough balance to send tokens to someone else. This ensures that a user can't pretend to have more tokens than she does.