ERC-20 tokens and contracts

4 min readNov 29, 2022

ERC-20 is an acronym that stands for Ethereum Requests for Comments 20, while the number 20 represents a unique ID to distinguish it from other standards. It’s a token standard proposed in 2015 by Fabian Vogelsteller.

ERC-20 is a set of rules that guide developers in building Ethereum-based tokens. At the outset, cryptocurrencies struggled to interact with each other, so the Ethereum community set a standard of rules for tokens built on Ethereum to follow and abide by. Every new token must submit relevant information to the Ethereum Improvement Proposal (EIP).

The definition of an ERC-20 contract includes its contract address and the total supply made available by it. Other options that provide more detail to users include the token’s name, symbol, and decimals.

The NAME of the token is the name by which the token should be known. There’s no restriction on the length of the name. However, it’s best to keep the name short because, in most wallets, it’ll be truncated if the name is long.

The SYMBOL represents the abbreviation or symbol of the token. It has no restriction on length either. It’s wise to keep it short.

Decimals represent the number of digits that come after the decimal place. It refers to how divisible a token can be from 0 to 18 or higher.

If the token contract is indivisible, set the decimals to 0. If it represents an item with a fixed number of decimal places, then set the decimal to that number. If the token contract doesn’t meet the above conditions, then set it to 18.

Total supply is a mandatory parameter in an ERC-20 contract. It is defined as the total number of issued tokens in a contract.

Functions of an ERC-20 contract

The balanceOf() function provides the number of tokens held by an account. User’s addresses are public and queried by anyone.

transfer() function transfers tokens from a message sender to the intended address or recipient address. Note that there are no checks to ensure that the address is valid, so it’s up to the sender to ensure the address’s accuracy.

The functions of allowance, transferFrom, and approve will be explained in this scenario 👇🏻

A user wants to buy something from a contract and pay with ERC-20 tokens. Since smart contracts cannot listen for events, they won’t be notified when they receive tokens.
A solution is to split the payment into two parts:

approve(): The user approves the contract for the transfer of a certain number of tokens, known as allowance.

Once an allowance has been created, the smart contract calls transferFrom() to take the allowed number of tokens from the user’s address.

transferFrom() transfers tokens from the initiator’s address to the recipient’s address, but only if the transaction initiator has a sufficient allowance approved by the owner (smart contracts or another address).

allowance() function provides the number of tokens that can be transferred from an address to another. Note: Any contract using allowance() must consider the amount of tokens in the holder’s address.

Characteristics of ERC-20 Tokens

ERC-20 tokens are fungible, which means that transaction histories are traceable even though each token’s code is identical.

They are transferable just like every cryptocurrency; they can be used for payment services and transferred from one address to another.

They must have a total supply. Most ERC-20 tokens may not have a fixed supply of tokens, but it’s necessary to have a total supply so the total number of tokens available can be known to the ecosystem.

Alternatives to ERC-20


There are a few other token standards that are similar to ERC-20 but perform different roles.

ERC-721 is a token standard for non-fungible tokens built on Ethereum, proposed in 2018 by the CryptoKitties team. This type of token helps prevent counterfeiting of assets like arts, music, etc.

ERC-1155 is a standard interface that combines the abilities of ERC-20 and ERC-721 (fungible and non-fungible tokens) to manage multiple token types. It was proposed in 2018 by Witek Radomski and the Enjin team.

ERC-777 is a fungible token standard seen as an improvement to ERC-20 proposed by Jacques Dafflon, Jordi Baylina, and Thomas Shababi. It’s similar to ERC-20, with differences in minting and burning tokens to speed up the transfer process.

Conclusion
Like other great technologies, ERC-20 has its faults. The ERC-223 proposal has additional features and safety measures to improve ERC-20, but it’s not ERC-20 compatible.

If you enjoyed this write-up and would like to reach out to me. This is my twitter handle — twitter.com/0xSalazar

Please remember to do your research. None of this is financial advice.

--

--

Salazar Slytherin
Salazar Slytherin

No responses yet