“Complete Guide: ERC20 Token Explained” – Content:
- How do Tokens work?
- What can you do with a Token?
- Why do we need the Token?
- What is an ERC20 Token?
- The 6 mandatory functions
- The 3 optional functions
- Why ERC20 Tokens are so useful
- Problems with ERC20 Token
- “ERC20 Token Explained” – Summarized
How do Tokens work?
Let´s quickly talk about some basics: tokens exist on the Ethereum platform. They are on top of a blockchain. So it is capable of storing transactions and also a virtual machine that can run smart contracts. Thus, Tokens benefit from this technology. So they aren’t independent and rely on a blockchain. The currency on the Ethereum network is Ether. But besides Ether, the system can also support tokens. So tokens can also work like currencies or represent shares of a company or other stuff.
What can you do with a Token?
First, let’s look at how tokens are made. 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. It also keeps track of each tokens holder balance. So to get some tokens you have to send some Ether to the smart contract. It 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. It also has to be able to transfer them and keep track of peoples balances. That sounds pretty easy but it’s also quite risky.
Why do we need the Token?
Once you create a smart contract, you cannot change it anymore. So if you made an error you can´t fix it. And that can be really bad. Imagine a bug inside your code that causes people to lose their tokens. Or even worse that would allow others to steal tokens.
And then there is the problem of compatibility. Each token contract can be very different from the other. So if you want your token to be available on an exchange, the trading market has to write custom code for your token. So they can talk to your contract and allow people to trade.
The same thing goes for wallet providers. Supporting hundreds of tokens would be very complex and takes a lot of time. So instead the Vitalik Buterin proposed a standard ERC20 Token.
What is an ERC20 Token?
ERC stands for “Ethereum Request for Comments” and 20 is just for some structure. So ERC20 is a guideline or standard for when you want to create your own token. It defines 6 mandatory and 3 optional functions that your smart contract have to implement.
The 6 mandatory functions are:
Total supply: When this limit is reached, the smart contract will refuse to create new tokens.
Balance Of: It is a method which has to return how many tokens a given address has.
Transfer: It takes a certain amount of tokens from the total supply. It then gives them to a user.
Transfer from: This can be used to transfer tokens between any two users who have them.
Approve: It verifies that your contract can give a certain amount of tokens to a user. It takes the total supply into account.
Allowance: It is almost the same as “approve”. But it also checks if one user has enough balance to send a certain amount of tokens to someone else.
The 3 optional functions are:
Name: You can give your token any name that is not already used.
Symbol: You can also use any symbol that is not already used.
Separability: You can choose how dividable your token is by specifying how many decimals it supports.
So To compare to give you and better understanding you can compare ERC20 Tokens to an interface. If you want your token to be an ERC20 Token you have to implement the ERC20 interface. So that forces you to implement these 6 methods.
Why ERC20 Tokens are so useful
Before there was the ERC20, everyone who wanted to create a token had to do a completely new one. So that meant that each token contract was different. All exchanges and wallets had to have custom code to support the token. With ERC20, however, exchange only has to implement this code once. And that is the reason why exchanges can add new tokens so quickly these days.
Problems with ERC20 Token
But the Ethereum ERC20 Token itself is not perfect. It is only a guideline. So people are free to implement the functions. But that has lead to some fatal errors. So to by some tokens you have to send some ether to the token contract. But some people tried to send other ERC20 tokens instead. If the contract was not designed with this in mind, it will result in your tokens being lost.
“ERC20 Token Explained” – Summarized:
- The ERC20 Token exists on the Ethereum Blockchain.
- It is a currency.
- They are based on smart contracts.
- It is just a guideline.
- It defines 6 mandatory and 3 optional functions that your smart contract have to have.
- The ERC20 Token is easy to create.
- Fatal errors in the code can result in losing a lot of tokens.