How ERC-20 tokens work and why they are needed at all
ERC-20 tokens are made specifically for the Ethereum platform.
They all follow a standard list of features so that they can be transferred, stored, and exchanged for other tokens in the Ethereum ecosystem. The Ethereum developers created these standards with three optional parameters and six mandatory ones.
Optional:
Token Name (token name);
Symbol (symbol);
Decimal (number of decimal places).
Required:
totalSupply;
balanceOf;
transfer;
transferFrom;
approve;
allowance.
Confused? Let’s look into the matter.
What is Ethereum anyway?
Ethereum is a decentralized computer network with two basic functions.
These functions include the blockchain itself for recording transactions and a virtual machine for executing smart contracts.
Thanks to this, Ethereum can support the execution of decentralized applications (DApps). DApps are built on Ethereum and can use the resources of the Ethereum system. The process is not free; developers pay for the use of platform resources with ETH coins, the native currency of the ecosystem.
Depending on their purpose, DApps can be used to create ERC20 token development company that can function as currencies, company shares, loyalty program points, or even proof of ownership of something.
What does smart contracts have to do with it?
ERC-20 tokens are created via smart contracts.
They are also designed to record token transactions and record wallet balances. Smart contracts are written in the Solidity language, which follows the logic of “IF THIS THEN THAT” (IFTTT).
Imagine a vending machine.
What happens after the smart contract creates a token?
From this point on, ERC-20 comes into play.
A token can be created, spent, traded, or transferred to another person. ERC-20 is the universal language of the Ethereum ecosystem, which allows you to exchange one token for another.
Imagine that you have created a crypto casino. Here players must use chips for ease of calculation among themselves. So, the player comes in, exchanges his money for chips and heads to the poker table.
The analogy is clear, but how exactly does it work?
Let’s take a closer look at each of the above-mentioned token parameters in our crypto casino.
Developers must follow the rules flawlessly.
Let’s start with the optional parameters:
Token Name: Blu Chip;
Symbol: BLU;
Decimal: 2.
Why 2? We want our tokens to be divisible to such an extent that the minimum player bet is at least 0.01 BLU. We could leave zero, and then the minimum bet would be 1 BLU, since in this case it is impossible to split the tokens. For the sake of clarity, we will not go into these details.
Let’s start with the main parameters. What is [totalSupply]?
[totalSupply] identifies the total supply of ERC-20 tokens created.
The first thing you need to decide is the number of chips. Let’s say there are 10 BLUs on our poker table for ten players.
What about [transfer]?
[transfer] allows you to transfer a certain number of tokens from their total number to the user’s wallet.
Before the game starts, each player must receive their BLU from the dealer. Everyone gets one chip.
What is the purpose of the [balanceOf] function?
The [balanceOf] function, when called, returns the number of tokens at a specific address.
In the first hand, five of the players looked at their cards and decided to skip the round. The remaining five placed 0.5 BLU each. Using the [balanceOf] function, we can determine the exact number of chips in each player’s hand.
How can I receive ERC-20 tokens from other users?
The [transferFrom] function allows you to transfer coins to other addresses.
Good news! Our player won 2.5 BLU in the first round. So that he can get his chips, we will use the [transferFrom] function.
Is it possible to fake a token?
Not really, the [approve] parameter checks each transaction against the total number of tokens.
Thanks to [approve], we can make sure that no visitors brought fake BLU with them.
Is there any way I can lie about the number of tokens in my wallet?
No.
Before the transaction itself, the [allowance] function checks the user’s balance. If there are not enough funds on it, she cancels the transfer.
Our establishment does not issue loans. If one player only has one chip, he will not be able to put 2 BLU on the line in the next round.
What are the advantages of ERC-20?
He makes everything easier.
Without create ERC20 token standard, developers could use their own rules and terminology in the coin code. For example, some would denote the total number of tokens with the [totalAmount] function, others with the [totalNumber] function.
In addition, exchanges would also have to take into account the specifics of each individual project. Thanks to ERC-20, new tokens can be automatically added to the exchange, moved between wallets, and so on. This standard also made it easier to create new coins, making Ethereum the most popular ICO platform in 2017.
What about problems?
The ERC-20 standard is not perfect.
In some situations, tokens may be destroyed. This happens when they are used as a means of payment for smart contracts instead of Ethereum. To fix the problem, the cryptocurrency community is currently working on a new standard called ERC-223.
It is currently not compatible with ERC-20, so developers can use the old standard for now. Once compatibility is achieved, most projects will be able to migrate to ERC-223.
In April 2018, several exchanges suspended deposits of Ethereum-based tokens due to a bug in the batchOverflow function. According to experts, the vulnerability was quite serious and could lead to the creation of a huge number of tokens out of thin air.
Are there any real use cases for ERC-20?
There are enough of them. Each Ethereum-based token is created according to the ERC20 token development standard.
According to the Etherscan service, more than 139 thousand different tokens have been created so far. This number continues to grow every day.
Among the most famous projects using the ERC-20 standard was the creation of EOS, the fifth-largest altcoin in the crypto market by capitalization. Before migrating to its own blockchain, Tron (10th place) also worked on the ERC-20 principle.
By the way, you can also create your own token to learn the basic principles of Ethereum.
Subscribe to my newsletter
Read articles from Deactivated User directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by