We all hear about ERC20 tokens, but what are those tokens and most importantly, what are they not? To start with, let’s quickly go over some basics: ERC20 tokens exists on the Ethereum platform and that in itself consists out of a blockchain that is capable of storing transactions and a virtual machine that is capable of running smart contracts.
The native currency on the Ethereum network is Ether. But besides Ether, it can also support other tokens and these can work like currencies but they can also represent shares of a company, loyalty points, gold certificates and so on. But we’re running ahead of it.
Let’s first take a look at how tokens come into existence. A token can be created by a smart-contract. This contract is not only responsible for creating tokens but also for managing transactions of the token and keeping track of each token holder’s balance. To get some tokens you have to send some Ether to the smart contract, which will then give you a certain amount of tokens in return. So when you want to create your own token, you write a smart-contract that can create tokens, transfer them and keep track of people’s balances.
That sounds pretty easy, but it’s also quite risky.
For starters, once a smart contract is deployed, it cannot be changed anymore, so if you made an error, you cannot fix it. That can be quite catastrophic. Imagine a bug inside your contracts code that causes people to lose their tokens or a bug that would allow others to steal tokens.
And then there is a problem of interoperability. Each token contract can be completely different from the other. So if you want your token to be available on an exchange, the exchange has to write custom code so they can talk to your contract and allow people to trade. Same thing goes for wallet providers. Supporting hundreds of tokens would be very complex and time consuming.
So instead, the community proposed a standard called ERC20. ERC stands for “Ethereum Requests for Comments” and 20 is just the number they assigned to a proposal that would create some structure in the wild west of tokens. ERC20 is a guideline or standard for when you want to create your own token.
It defined 6 mandatory functions that your smart contract should implement and 3 optional ones. To start with, you can optionally give your token a name, a symbol and you can control how dividable your token is by specifying how many decimals it supports. The mandatory functions are a bit more complex, for starters you have to create a method that defines the total supply of your token. When this limit is reached, the smart contract will refuse to create new tokens.
Next up is the ‘balanceOf’ method, which has to return how many tokens a given address has. Then there are two transfer methods: `transfer` which takes a certain amount of tokens from the total supply and gives them to a user and `transferFrom` which can be used to transfer tokens between any two users who have them. Finally, there is the `approve` and `allowance` method. `Approve` verifies that your contract can give a certain amount of tokens to a user, taking into account the total supply. The `allowance` method is almost the same except that it checks if one user has enough balance to send a certain amount of tokens to someone else. If you know something about object oriented programming, then you can compare ERC20 to an interface.
If you want your token to be an ERC20 token, you have to implement the ERC20 interface and that forces you to implement these 6 mothods. Before there was the ERC20 standard, everyone who wanted to create a token had to reinvent the wheel. And that meant that each token contract was slightly different and that exchanges and wallets had to write custom code to support your token. With ERC20 however, exchanges and wallet providers only have to implement this code once.
That’s why exchanges can add new tokens to quickly and why wallets like MyEtherWallet has support for all ERC20 tokens without having to be updated.
So how easy would it be to create your own token? Well there’s a website called TokenFactory that does it all for you. You just enter what the total supply of your token should be, how you want to call it, how many decimals it should support and what symbol it should have. After entering all this, the website creates a token contract for you and adds it to the Ethereum blockchain. It’s super easy and almost effortless.
So effortless in fact, that the website Etherscan has a list of 36,000 known ERC20 tokens and it’s estimated that in 2017, over 4 billion dollars was raised by selling tokens in an ICO. However these tokens were not always clean. Some were really overhyped and many people got scammed into purchase tokens that were essentially worthless. But now we’re getting a bit distracted.
ERC20 is a great standard that has propelled the use of tokens. But ERC20 itself is not perfect. It’s only a guideline and people are free to implement the required functions however they like. That has lead to some interesting problems. For instance: to buy some tokens you have to send some ether to the token contract. But some people tried sending other ERC20 tokens instead. If the contract was not designed in this in mind, it will result in your tokens being lost. In fact, it was estimated that by Deember 2017, well over 3 million dollars have been lost because of this flaw.
So to solve this, the community is already working on extending the ERC20 standard with the ERC223 standard. This warns token creators about these risks and offers some workarounds.