Contents

  • Introduction

  • What is the ERC-20 standard?

  • A brief reminder about Ethereum tokens

  • How are ERC-20 tokens created?

  • What can ERC-20 tokens do?

    • Stablecoins

    • Tokens financiers

    • Utility tokens

  • Can you mine ERC-20 tokens?

  • Advantages and disadvantages of ERC-20 tokens

    • Advantages of ERC-20 tokens

    • Disadvantages of ERC-20 tokens

  • ERC-20, ERC-1155, ERC-223, ERC-721, what are the differences?

  • To conclude


Introduction

Ethereum was founded by Vitalik Buterin in 2014, positioning itself as an open-source platform for launching decentralized applications (DApps). Buterin's motivation for creating a new blockchain is based on Bitcoin's lack of flexibility.

Since its launch, the Ethereum blockchain has attracted developers, businesses and entrepreneurs, giving rise to a growing industry of users launching smart contracts and distributed applications.

In this article, we will look at the ERC-20 standard, an important framework for creating tokens. Although specific to the Ethereum network, the framework has also inspired other blockchain standards, such as Binance Chain's BEP-2.


What is the ERC-20 standard?

On Ethereum, an ERC is an Ethereum Request for Comments. These are technical documents that define the standards for programming on Ethereum. These should not be confused with Ethereum Improvement Proposals (EIPs), which, like Bitcoin's BIPs, suggest improvements to the protocol itself. Rather, ERCs aim to establish conventions that facilitate interaction between applications and contracts.

Defined by Vitalik Buterin and Fabian Vogelsteller in 2015, ERC-20 offers a relatively simple format for Ethereum-based tokens. By following his blueprint, developers don't need to reinvent the wheel. Instead, they can build on a foundation already in use in the area.

Once new ERC-20 tokens are created, they are automatically interoperable with services and software supporting the ERC-20 standard (software wallets, hardware wallets, exchanges, etc.).

It should be noted that the ERC-20 standard was developed by an EIP (specifically, EIP-20). This occurred a few years after the initial proposal, due to its widespread use. However, even years later, the name “ERC-20” stuck.


A brief reminder about Ethereum tokens

Unlike ETH (Ethereum's native cryptocurrency), ERC-20 tokens are not held by accounts. Tokens only exist in a contract, which is like a standalone database. It specifies token rules (name, symbol, divisibility) and maintains a list that associates user balances with their Ethereum addresses.

To move tokens, users must send a transaction to the contract asking them to allocate part of their balance elsewhere. For example, if Alice wants to send 5,000 BinanceAcademyTokens to Bob, she calls a function in the BinanceAcademyToken smart contract to ask him to do so.


Utilisateurs interagissant avec un smart contract


His call is contained in what appears to be a regular Ethereum transaction that pays 0 ETH to the token contract. The call is included in an additional field in the transaction, which specifies what Alice wants to do. In our case, transfer tokens to Bob.

Even if she doesn't send ether, she still has to pay a fee to have her transaction included in a block. If she does not have ETH, she must obtain some before transferring the tokens.

Here's a real-life example of the above on Etherscan: Someone makes a call to the BUSD contract. You can see that tokens have been transferred, and fees have been paid, even though the value field indicates that 0 ETH was sent.

Now that we understand the basics, let's look under the hood to better understand the structure of a typical ERC-20 contract.


How are ERC-20 tokens created?


Illustration de la création d'un token ERC-20


To be ERC-20 compliant, your contract must include six mandatory features: totalSupply, balanceOf, transfer, transferFrom, approve, and allowance. Additionally, you can specify optional functions, such as name, symbol, and decimal. The names of these functions may make it clear to you what they do. If not, don't worry, we'll explain it below.

Here are the functions as they appear in the Solidity language designed specifically for Ethereum.


totalSupply

function totalSupply() public view returns (uint256)

When called by a user, the above function returns the total supply of tokens that the contract holds.


balanceOf 

function balanceOf(address _owner) public view returns (uint256 balance)

Unlike totalSupply, balanceOf takes a parameter (an address). When called, it returns the balance of tokens held by that address. Remember that accounts on the Ethereum network are public, so you can query the balance of any user as long as you know their address.


transfer

function transfer(address _to, uint256 _value) public returns (bool success)

transfer transfers tokens from one user to another. Here you indicate the address you want to send the money to and the amount to transfer.

When called, transfer triggers something called an event (the transfer event, in this case), which essentially tells the blockchain to include a reference to it.


transferFrom

function transferFrom(address _from, address _to, uint256 _value) public returns (bool success)

The transferFrom function is a convenient alternative to transfer that allows a little more programmability in decentralized applications. Like transfer, it is used to move tokens, but the tokens do not necessarily have to belong to the person calling the contract.

In other words, you can authorize a person, or another contract, to transfer funds on your behalf. One possible use case involves paying for subscription-based services, where you don't want to manually send a payment every day/week/month. Instead, you let a program do it for you.

This function triggers the same event as transfer.


approve

function approve(address _spender, uint256 _value) public returns (bool success)

approve is another useful function from a programmability point of view. Thanks to this function, you can limit the number of tokens that a smart contract can withdraw from your balance. Without it, the contract may malfunction (or become malicious) and this may result in the loss of all your funds.

Let’s return to our subscription model example. Let's say you have a large amount of BinanceAcademyTokens and want to set up weekly recurring payments for a streaming DApp. You are busy reading Binance Academy content day and night. So you don't want to take the time every week to create a transaction manually.

You have a huge BinanceAcademyTokens balance, way beyond what is needed to pay for the subscription. To prevent the DApp from draining them all, you can set a limit with approve. Let's assume your subscription costs one BinanceAcademyToken per week. If you cap the approved value at twenty tokens, then you could have your subscription paid automatically for five months.

At worst, if the DApp tries to withdraw all your funds or a bug is discovered, you can only lose twenty tokens. It may not be the ideal solution, but it's certainly more attractive than losing all your funds.

When called, approve triggers the approval event. Like the transfer event, it writes data to the blockchain.


allowance

function allowance(address _owner, address _spender) public view returns (uint256 remaining)

allowance can be used in conjunction with approve. When you have granted contract authorization to manage your tokens, you can use it to check how much more can be withdrawn. For example, if your subscription has consumed twelve of your twenty approved tokens, calling the allowance function should return a total of eight.


Optional functions

The functions presented previously are mandatory. But the functions, name, symbol and decimal do not need to be included, but they can make your ERC-20 contract a little prettier. Respectively, they allow you to add a human-readable name, define a symbol (e.g. ETH, BTC, BNB), and specify the number of decimal places to which the tokens are divisible. For example, tokens used as currencies may be more divisible than a token that represents ownership of an asset.


Check out this example on GitHub to see these elements in an actual contract.


What can ERC-20 tokens do?


Illustration des différentes utilisations des tokens ERC-20


Putting all the above functions together, we get an ERC-20 contract. We can query the total supply, check balances, transfer funds and give permissions to other DApps to manage the tokens.

Much of the appeal of ERC-20 tokens is their flexibility. The defined conventions do not limit development, so parties can implement additional functionality and set specific parameters to meet their needs.


Stablecoins

Stablecoins (tokens tied to fiat currencies) often use the ERC-20 token standard. The BUSD contract transaction we mentioned earlier is an example, and most major stablecoins are also available in this format.

For a classic fiat-backed stablecoin, an issuer holds reserves of euros, dollars, etc. Then, for each unit in reserve, they issue a token. This means that if $10,000 were stuck in a vault, the issuer could create 10,000 tokens, each exchangeable for $1.

It's pretty easy to implement on Ethereum, technically speaking. An issuer simply launches a contract with 10,000 tokens. Then, it distributes them to users with the promise that they can later exchange the tokens for a proportional amount of fiat currency.

Users can do a number of things with their tokens: they can buy goods and services or use them in DApps. They can also ask the issuer to exchange them immediately. In this case, the issuer burns the returned tokens (making them unusable) and withdraws the corresponding amount of fiat from its reserves.

The contract that governs this system, as mentioned previously, is relatively simple. However, launching a stablecoin requires a lot of work on external factors such as logistics, regulatory compliance, etc.


Tokens financiers

Financial tokens are similar to stablecoins. Contract-wise, the two might even be the same because they work the same way. The distinction occurs at the transmitter level. Financial tokens represent securities, such as stocks, bonds or physical assets. Often (although not always) they represent the holder's interest in a business or property.


Utility tokens

Utility tokens are perhaps the most common type of tokens today. Unlike the previous two types, they are not backed by another asset. If asset-backed tokens are like shares in an airline, utility tokens are like loyalty programs: they serve a function, but have no external value. Utility tokens can serve a myriad of use cases, serving as in-game currency, fuel for decentralized applications, loyalty points, and much more.


➟ Do you want to get started with cryptocurrencies? Buy bitcoins on Binance!


Can you mine ERC-20 tokens?

You can mine Ether (ETH), but the tokens are not minable, we say they are issued when new tokens are created. When a contract is launched, developers distribute the offer based on their plans and roadmap.

This is typically done through an Initial Coin Offering (ICO), Initial Exchange Offering (IEO), or Financial Token Offering (STO). You may encounter variations of these acronyms, but these concepts are quite similar. Investors send ether to the contract address and, in return, receive new tokens. The money collected is used to finance the further development of the project. Users expect to be able to use their tokens (immediately or at a later date) or resell them for a profit as the project grows.

Token distribution does not need to be automated. Many crowdfunding events allow users to pay in different digital currencies (such as BNB, BTC, ETH, and USDT). The respective balances are then assigned to the addresses provided by the users.


Advantages and disadvantages of ERC-20 tokens

Advantages of ERC-20 tokens

Fongible

ERC-20 tokens are fungible, each unit is interchangeable with another. If you hold a BinanceAcademyToken, it doesn't matter which specific token you own. You could trade it for someone else's, and they would still be the same, like cash or gold.

This is ideal if your token aims to become a sort of currency. You wouldn't want individual units with distinctive traits, which would make them non-fungible. Thus, some tokens could be more or less valuable than others, which would undermine their usefulness.


Flexibility

As we saw in the previous section, ERC-20 tokens are highly customizable and can be adapted to many different applications. For example, they can be used as in-game currency, in loyalty programs, as digital collectibles, or even to represent property rights and artwork.


The popularity of ERC-20 in the cryptocurrency industry is a very compelling reason to use it as a model. There are a plethora of exchanges, wallets and smart contracts already compatible with the recently launched tokens. Additionally, there is plenty of developer support and documentation.


Disadvantages of ERC-20 tokens

Scalability

As with many cryptocurrency networks, Ethereum is not immune to growing pains. In its current form, it is not very scalable: trying to send a transaction at peak times results in high fees and delays. If you launch an ERC-20 token and the network is congested, its usage may be affected.

This is not an Ethereum-exclusive problem. Rather, it is a necessary compromise for all secure and distributed systems. The community plans to resolve these issues when migrating to Ethereum 2.0, which will implement upgrades like Ethereum Plasma and Ethereum Casper.

To learn more about scalability issues, see Blockchain Scalability: Sidechains and Payment Gateways.


Scams

While not a problem with the technology itself, the ease with which a token can be launched can be seen as a disadvantage in some respects. It takes very little effort to create a simple ERC-20 token, meaning anyone could do it, whether for good or ill.

So you need to be careful about what you invest in. There are a number of pyramid and Ponzi schemes disguised as blockchain projects. Do your own research before investing to form your own ideas about the legitimacy of an opportunity.

 

ERC-20, ERC-1155, ERC-223, ERC-721, what are the differences?

ERC-20 was the first (and, to date, most popular) Ethereum token standard, but it is far from the only one. Over the years, many others have emerged, either proposing improvements on the ERC-20 or trying to achieve different goals.

Some of the less common standards are those used in non-fungible tokens (NFTs). Sometimes it is beneficial for your use case to have unique tokens with different attributes. If you want to tokenize a unique piece of art, an asset in a game, etc., one of these contract types might be more interesting.

The ERC-721 standard, for example, was used for the immensely popular CryptoKitties DApp. Such a contract provides an API allowing users to issue their own non-fungible tokens and encode metadata (images, descriptions, etc.).

The ERC-1155 standard can be considered an improvement of the ERC-721 and ERC-20 standards. It presents a standard that supports fungible and non-fungible tokens in the same contract.

Other options like ERC-223 or ERC-621 aim to improve usability. The first implements protective measures to prevent accidental transfers of tokens. The second adds additional functions to increase and decrease the token supply.

To learn more about NFTs, visit A ​​Guide to Crypto Collectibles and Non-Fungible Tokens (NFTs).


To conclude

For years, the ERC-20 standard has dominated the cryptoasset space, and it's not hard to see why. With relative ease, anyone can deploy a simple contract to fit a wide range of use cases (utility tokens, stablecoins, etc.). That said, ERC-20 lacks some of the features implemented by other standards. It remains to be seen whether subsequent types of contracts will be put in place.