What are ERC-20 tokens? In the following article, we are going to explain it in great detail.
Vitalik Buterin founded Ethereum in 2014 as an open-source platform for creating decentralized applications (DApps).
Because the Bitcoin protocol was limited in its flexibility, Buterin was motivated to create a new blockchain.
The Ethereum blockchain has grown into a thriving ecosystem of developers, businesses, and entrepreneurs since its launch, attracting a growing community of users developing smart contracts and distributed applications.
The ERC-20 standard is a crucial framework for creating tokens, and we’ll examine it in this post.
Although it’s specially created for the Ethereum network, the framework also inspired other blockchain standards such as Binance Chain’s BEP-2.
What does ERC-20 do?
ERCs are Ethereum Request for Comments documents that describe standards for programming on Ethereum. They are distinct from Ethereum Improvement Proposals (EIPs), which, like Bitcoin’s BIPs, seek to improve the protocol itself. ERCs, on the other hand, seek to establish standards that make it easier for applications and contracts to work together.
In 2015, Vitalik Buterin and Fabian Vogelsteller created ERC-20, a simple format for Ethereum-based tokens. Developers can utilise an existing foundation to build their own tokens rather than starting from scratch.
New ERC-20 tokens can be created once the ERC-20 standard is implemented (wallets, hardware wallets, exchanges, and other services and software). They will automatically be interoperable.
The ERC-20 standard was turned into an EIP (particularly, EIP-20) a couple of years after its initial proposal due to its widespread adoption. However, the moniker “ERC-20” has remained in use years later.
We recommend watching the following video before continuing to read this article:
Ethereum tokens explained
Unlike ETH (Ethereum’s native cryptocurrency), ERC-20 tokens are not held by accounts. They exist inside a contract, which is similar to a self-contained database. It defines the tokens’ characteristics (name, symbol, divisibility) and tracks user balances using Ethereum addresses.
Users must send a transaction to the contract asking it to allocate some of their balance elsewhere in order to move tokens.
In this case, if Alice wants to send 5,000 of a certain token to Bob, she calls a function inside the token smart contract asking it to do so.
The extra field in the transaction specifies what Alice wants to do—in our case, transfer tokens to Bob—for 0 ETH.
She must still pay a fee denominated in ether to have her transaction included in a block, even though she is not sending any ether. If she has no ETH, she must get some before transferring the tokens.
Here’s a real-world example of the above on Etherscan: someone is making a call to the BUSD contract. You can see tokens being transferred and a fee being paid, even though the Value field indicates that no ETH has been sent.
Let’s look at the inner workings of an ERC-20 contract to better understand its structure.
What is the process for creating ERC-20 tokens?
Your contract must include six essential ERC-20 functions: totalSupply, balanceOf, transfer, transferFrom, approve, and allowance.
In addition, you may include optional functions like name, symbol, and decimals.
You may be able to deduce what those functions do from their names. If not, don’t worry – we’ll explain them.
The following is a list of the built-in functions in Ethereum’s purpose-specific Solidity language.
- function totalSupply() public view returns (uint256)
A function that returns the total supply of tokens.
The above function returns the amount of tokens the contract holds when a user requests it.
- function balanceOf(address _owner) public view returns (uint256 balance)
balanceOf takes a parameter (an address) and returns the balance of that address’s token holdings, unlike totalSupply.
On the Ethereum network, accounts are public, so you can query any user’s balance if you know their address.
- function transfer(address _to, uint256 _value) public returns (bool success)
transfer aptly transfers tokens from one user to another. Here, you provide the address you want to send to and the amount to transfer.
When the function is public, it returns true if the transfer is successful or false if it is not (or it throws an exception).
You specify the address you want to send to and the amount to be transferred in order to transfer tokens properly.
An event (event transfer in this case) is triggered when a transfer is called, signalling the blockchain to include a reference to it.
- function transferFrom(address _from, address _to, uint256 _value) public returns (bool success)
A successful call to transferFrom(…) returns true if the transfer was successful.
In decentralized applications, the transferFrom function is a great alternative to transfer, as it allows for more programmability.
Like transfer, it moves tokens, but those tokens don’t necessarily need to belong to the person calling the contract.
You can let another contract or person execute payments on your behalf using Ethereum. For example, you may want to pay for a subscription-based service and not have to send payments daily, weekly, or monthly. Instead, you let a program handle it for you.
This function triggers the same event as transfer.
- function approve(address _spender, uint256 _value) public returns (bool success)
It returns true if the transaction succeeds.
approve is another great feature from a programmable perspective. With this function, you can restrict the number of tokens that a smart contract can withdraw from your balance.
Without it, you might end up with a faulty (or exploited) contract that steals all of your tokens.
Suppose that you hold a lot of certain tokens and want to set up a recurring payment to a streaming DApp. You are very busy day and night, so you don’t want to spend time each week making a transaction manually.
You currently possess a large number of certain tokens, more than enough to pay for your subscription.
In order to prevent the DApp from consuming them all, you may limit the amount you approve. For example, if you want your subscription to be paid for automatically for five months, you must restrict the amount you approve to twenty tokens.
The worst thing that can happen if the DApp attempts to withdraw all of your funds or if a bug is discovered is that you lose twenty tokens. It may not be ideal, but it is certainly more appealing than losing all your holdings.
When an approval event is triggered, it writes data to the blockchain. It approves when called.
- function allowance(address _owner, address _spender) public view returns (uint256 remaining)
A function to check the remaining allowance of an address.
It is possible to use the approve function in conjunction with allowance to check how many tokens a contract has been given permission to manage.
For example, if your subscription has used up twelve of your twenty approved tokens, the allowance function should return eight.
The optional functions
While the previously-discussed features are required, name, symbol, and decimal positions are optional.
In other words, you can add a human-readable name, set a symbol (such as ETH, BTC, or BNB), and specify how many decimal places tokens are divisible to.
For example, a token that represents a property may benefit from being more divisible than a token that functions as a currency.
What are the use of ERC-20 tokens?
We’ve created an ERC-20 contract by assembling all of the aforementioned features.
We can query the total supply, check balances, transfer funds, and permit other DApps to manage tokens for us.
The ERC-20 protocol is popular because of its versatility. Parties can establish custom values and add additional features as long as they adhere to the conventions.
Most major stablecoins use the ERC-20 token standard, which is commonly used for stablecoins pegged to fiat currencies.
The transaction to the BUSD contract, which we referenced earlier, is one example, and most major stablecoins are also available in this format.
In order to make a fiat-backed stablecoin, an issuer holds reserves of euros, dollars, etc. For every token issued, they keep a reserve of one unit of the fiat currency. If $10,000 were locked away in a vault, the issuer could create 10,000 tokens, each redeemable for $1.
Issuing tokens on Ethereum is simple, technologically speaking. A contract is created with 10,000 tokens. Then, users are given tokens in exchange for their promise to pay an equivalent amount of fiat currency later.
Users can employ their tokens to buy items or use them in DApps, or they can request that the issuer exchange them immediately. The issuer burns the returned tokens (making them unusable) and withdraws the correct amount of money from his reserves.
As mentioned previously, the contract governing this system is relatively simple. However, creating a stablecoin requires a lot of work on external factors such as logistics, regulatory compliance, etc.
Stablecoins and security tokens both work in the same way at the contract level.
The issuer, not the contract, determines whether a token represents a security, such as a stock, bond, or physical asset. Security tokens are represented by securities, such as stocks, bonds, or physical assets.
A token may grant the holder some sort of stake in a company or product, although this is not always the case.
The most widespread tokens in use today are utility tokens. They are not backed by anything, unlike the previous two offerings.
If asset-backed tokens are comparable to shares in an airline firm, then utility tokens are comparable to frequent-flyer programs: they serve a purpose but have no outside value.
Tokens can be utilised for a variety of purposes, including in-game currency, fuel for decentralized applications, loyalty points, and much more.
Are ERC-20 tokens mineable?
ETH tokens are not mineable; we say they are minted when new ones are created.
Developers distribute the supply according to their plans and roadmap when a contract is launched.
An ICO, IEO, or STO is typically how this occurs. There are several similar terms for these processes, but the meaning is essentially the same.
Investors send ether to a contract address and receive new tokens in return. Money is raised to fund the project’s future development. Users expect to be able to either use their tokens right away or resell them for a profit as the project develops.
The tokens can be distributed in different ways, but it doesn’t have to be automated. Crowdfunding initiatives frequently permit users to pay with a variety of digital currencies such as BNB, BTC, ETH, and USDT (among others). The balances are then distributed to the addresses provided by the users.
Pros and cons of ERC-20 tokens
Each ERC-20 token is fungible—meaning that every unit can be substituted for another. It wouldn’t matter whether you had a certain token or another ERC-20 token; you could exchange them and they would be functionally identical, just like cash or gold.
Non-fungible tokens are the best choice if your token is intended to be a currency.
Individual units with unique characteristics would make them non-fungible, and this would make some tokens more or less valuable than others, undermining their function.
ERC-20 tokens can be customized for many different purposes, as we learned in the previous section. They can be used as in-game currencies, loyalty point systems, digital collectibles, or even to symbolize fine art and property rights, for example.
The fact that ERC-20 is widely used in the cryptocurrency world is a compelling reason to adopt it as a model.
Furthermore, there are a lot of exchanges, wallets, and smart contracts that are already compatible with new tokens. Developer support and documentation are plentiful.
The Ethereum network has a number of limitations that prevent it from scaling well—high fees and delays occur when the network is busiest.
If you launch an ERC-20 token, its usability may be affected if the network becomes congested.
While Ethereum has its own set of scalability problems, the community is working on addressing them with the Ethereum 2.0 upgrade, which will implement upgrades like Ethereum Plasma and Ethereum Casper improvements.
The simplicity with which a token can be created might be considered a downside in some respects, not an issue with the technology itself. Anyone can create an ERC-20 token, which requires minimal effort, therefore.
Therefore, you should be cautious about where you invest your money. There are a number of Pyramid and Ponzi schemes masquerading as blockchain initiatives. Do your own research before investing so that you can come to your own conclusions whether a venture is legitimate or not.
What are the distinctions between ERC-20, ERC-1155, ERC-223, and ERC-721?
Many other token standards have been created for Ethereum aside from ERC-20, the first and most popular one (up to now). ERC-20 has been revised over the years, but other alternatives have also been proposed.
Non-fungible tokens (NFTs) utilize certain less common standards. In certain cases, your job might benefit from tokens with unique attributes. If you wanted to tokenize a one-of-a-kind piece of artwork, for example, one of these contracts might be more suitable.
Non-fungible tokens can be created using the ERC-721 standard, for example. The API allows users to create their own tokens and to encode metadata (images, descriptions, etc.). CryptoKitties, a wildly popular DApp, uses this standard.
ERC-1155 may be viewed as an improvement on both ERC-721 and ERC-20 standards. It defines a protocol that allows for both divisible and non-divisible tokens to exist on the same contract.
Additional standards such as ERC-223 and ERC-621 are designed to boost usability. The former prevents accidental token transfers by implementing safeguards. The latter adds extra features for increasing and lowering token quantities, in order to increase usability.
For a long time, the ERC-20 standard has dominated the crypto asset industry, and it’s simple to see why.
Anyone can create a simple contract to suit a wide variety of uses (utility tokens, stablecoins, etc.), but ERC-20 lacks some of the features other standards bring to life. It remains to be seen whether subsequent contract types will succeed it.
Zookram is the ultimate guide to learning web3 + crypto. We cover everything you need to know, from how to buy each cryptocurrency to how to mint NFTs.