Contents
Ethereum was written by Vitalik Buterin in Founded in 2014, it is positioned as an open source platform to launch decentralized applications (DApps). Buterin's motivation for creating this new blockchain stemmed largely from the lack of flexibility in the Bitcoin protocol.
Since its inception, the Ethereum blockchain has attracted many developers, companies and entrepreneurs, spawning an emerging industry of smart contracts and distributed applications launched by users.
In this article, we will look at the ERC-20 standard, which is an important framework for creating tokens. Although only applied to the Ethereum network, it is the inspiration for other blockchain standards such as Binance Chain’s BEP-2.
In Ethereum, the full name of ERC is Ethereum Request for Comments, that is, Ethereum Comments Request. These technical documents outline Ethereum’s programming standards. This is not to be confused with the Ethereum Improvement Proposal (EIP), which is similar to Bitcoin’s BIP and is a proposal for improvements to the protocol itself. The goal of ERC is to establish a protocol that facilitates interaction between applications and contracts.
Developed and written in 2015 by Vitalik Buterin and Fabian Vogelsteller, ERC-20 proposes another relatively simple format for Ethereum-based tokens. As long as the outline is followed, developers don't need to reinvent the wheel and can build directly on what's going on across the industry.
When new ERC-20 tokens are created, they automatically interoperate with services and software that support the ERC-20 standard (software wallets, hardware wallets, trading platforms, etc.).
It should be noted that the ERC-20 standard has been developed into EIP (especially EIP-20). At this time, several years have passed since the original widely circulated proposal, but even after several years passed, the name "ERC-20" has been retained.
Unlike ETH (Ethereum’s native cryptocurrency), ERC-20 tokens It is not deposited into the account, but only exists inside the contract, like an independent database. It specifies the rules for the token (i.e. name, symbol, divisibility) and maintains a list of Ethereum addresses that map user balances.
In order to transfer tokens, users must send a transaction to a smart contract, asking the contract to allocate part of the balance elsewhere. For example, if Alice wants to send 5,000 Binance Academy Tokens to Bob, she will call a function in the corresponding smart contract to execute the instruction.
Her calling instructions contain seemingly regular Ethereum transactions. This transaction paid 0 ETH to the token contract. This call is included among other fields of the transaction and specifies Alice's intention - in this case, she wants to transfer the tokens to Bob.
Even if she does not send ether, she must pay a specified fee to add the transaction to the block. If you don't have ETH, you should pre-deposit some ETH before transferring your tokens.
The following is a real case in Etherscan: someone called a BUSD contract. You will see that the tokens were transferred and the fee was paid, although the value field shows that 0 ETH was sent.
Next, we step up the pace and gain an in-depth understanding of the typical ERC-20 contract structure.
According to the ERC-20 standard, your contract must set six mandatory Function:totalSupply,balanceOf、transfer、transferFrom、approve span>andallowance. Additionally, optional functions can be specified, such as name, symbol and decimal strong>. You can understand the function function based on the name. Don’t worry if you don’t understand it. We will analyze it one by one below.
The following are functions rendered through Ethereum-specific Solidity language.
function totalSupply() public view returns (uint256)
After the user calls the above function, the total supply of tokens held by the contract will be returned.
function span> balanceOf(address _owner) public view returns (uint256 balance)
Different fromtotalSupply,balanceOfuses an address as a parameter. After the call, the system returns the token holding balance of the address. Remember, accounts in the Ethereum network are public and transparent. You can check the balance of any user as long as you know the address.
function span> transfer(address _to, uint256 _value) public returns (bool success)transfer function supports users to transfer tokens to each other. You need to provide the token receiving address and transfer amount.
After calling, transfer will trigger the event (in this case Below is the "Transfer" event), the basic function is to tell the blockchain to contain a reference to this function.
transferFrom
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success )transferFromThe function istransfer function, effectively improving programmability in decentralized applications. Similar to thetransfer function, it is used to move tokens, but these tokens do not necessarily belong to the calling contract User.
In other words, you can authorize another person or another contract to transfer funds on your behalf. For example, if you don't want to manually pay for a subscription service on a daily/weekly/monthly basis, you can let the program do the work for you.
The event triggered by this function is the same as transfer.
approve
function approve(address _spender, uint256 _value) public returns (bool success) pre>From a programming perspective, approve is another very useful function. It is possible to limit the number of tokens that a smart contract can withdraw from the balance. Without it, running contracts may become invalid (or exploited) and all funds are at risk of being stolen.
Take the subscription model as an example again. Let’s say you hold a large amount of Binance Academy tokens and want to set up recurring weekly payouts for your streaming DApp. I am too busy reading Binance Academy articles to spend time manually creating trades every week.
The large balance of Binance Academy tokens held far exceeds the fees required to pay for the subscription. In order to prevent the DApp from paying out all the assets, you can use approve to set a limit. Assuming your subscription costs 1 Binance Academy token per week, your subscription will be automatically paid over 5 months if the approval limit is 20 tokens.
If the program goes wrong and the DApp tries to withdraw all the funds, you will only lose up to 20 tokens. While losing your tokens is upsetting, the outcome is much better than losing all your assets.
After calling this function, approve will trigger approval strong> event, like the transfer function, it will write data to the blockchain.
allowance
function allowance(address _owner, address _spender) public view returns (uint256 remaining)allowance can be used withapprove used in combination. If token management rights are granted to the contract, you can check the withdrawable balance of the token through it. For example, assuming that the subscription service uses 12 of the 20 approved tokens, calling the allowance function will return a total of 8 tokens.
Other optional functions
The contents discussed above are mandatory functions. On the other hand, name, symbol and decimal are optional functions, but they can make ERC-20 more complete. These functions respectively support adding a human-readable name, setting the symbol (i.e. ETH, BTC, BNB) and specifying the number of decimal places the token can be divided into. For example, tokens used as currency are more divisible and therefore more beneficial than tokens used to represent ownership of property.
Check out this example on GitHub to see how these elements would look in a real contract.
What functions does ERC-20 have?
Aggregating all the above functions, we get an ERC-20 contract. We can query the total supply, view balances, transfer funds and authorize other DApps to manage tokens on our behalf.
The flexibility of ERC-20 tokens is a huge advantage. The established agreement does not limit development, and each party can launch other functions and set specific parameters according to their own needs.
Stablecoins
Stablecoins (tokens linked to fiat currencies) usually use the ERC-20 token standard. The BUSD contract transaction mentioned above is a typical example, and most stablecoins also use this form.
For stablecoins backed by mainstream fiat currencies, the issuer can hold reserves such as euros and US dollars, and then issue tokens for each unit in the reserves. This means that if $10,000 is deposited into the vault, the issuer can create 10,000 tokens, each worth $1.
From a technical perspective, it is easy to implement in Ethereum. The issuer simply launches a contract with 10,000 tokens and then distributes the tokens to users, promising that they can exchange the tokens for a certain percentage of fiat currency in the future.
Users can use their tokens to perform a variety of operations, including purchasing goods and services and applying to DApps. Alternatively, the issuer can be required to redeem these tokens immediately. In this case, the issuer can also destroy the returned tokens (let them expire) and withdraw an equivalent amount of fiat from the reserve.
As mentioned earlier, the contracts governing this system are relatively simple. However, launching a stablecoin requires attention to many other external factors (such as logistics, compliance, etc.) and a lot of effort.
Security tokens
Security tokens are similar to stablecoins and can even be completely Consistent because both operate in the same way. The difference lies in the issuer: Security tokens represent securities such as stocks, bonds, or real assets. They usually, although not always, grant the holder shares in a business or commodity.
Utility Tokens
Utility tokens are probably the most common type of token today. Unlike the previous two tokens, utility tokens are not backed by any real assets. If airline shares represent asset-backed tokens, utility tokens are like frequent flyer programs: they have some functionality, but no external value. Utility tokens can serve numerous needs, such as being used as in-game currency, fuel for decentralized applications, and loyalty points.
➠ Want to start your cryptocurrency journey? Welcome to Binance to buy Ethereum!
Can I participate in ERC-20 token mining?
You can participate in Ethereum (ETH) mining, but the tokens cannot be mined – We call the creation of new tokens minting. Once the contract goes live, developers will allocate supply according to plans and roadmaps, generally through an initial coin offering (ICO), initial exchange offering (IEO) or security token offering (STO). Finish. You may come across several variations of these acronyms, but the concepts are very similar. Investors send ether to the contract address and receive new tokens in return. Funds raised will be used to fund future development of the project. Users expect to be able to use their tokens (immediately or later) or resell them at a profit as the project grows.
Token issuance may not be performed automatically. Many crowdfunding campaigns support users to complete payments using various digital currencies (such as BNB, BTC, ETH, and USDT), and then distribute the corresponding balance to the address provided by the user.
Pros and cons of ERC-20 tokens
Advantages of ERC-20 tokens
Fungibility
ERC-20 tokens are fungible and all units can be exchanged for each other. When it comes to Binance Academy Tokens, it’s the same regardless of which specific coin you hold. You can trade with other people and the tokens function the same, similar to cash or gold.
This is ideal if the token you hold hopes to develop into a currency of some kind. Tokens with distinct characteristics lose their fungibility and do not meet your requirements. This can cause certain tokens to be worth less or more than similar tokens, defeating the original purpose.
Flexible
As discussed in the previous chapter, ERC-20 tokens are extremely customizable and can Tailor-made solutions for different applications. Examples include being used as in-game currency, loyalty points for programs, digital collectibles, or even representing artwork and property ownership.
Popularity
ERC-20 is gaining popularity in the cryptocurrency field, and the blueprint based on it is very convincing. Numerous exchanges, wallets and smart contracts are now compatible with various newly launched tokens. Additionally, developer support and documentation are quite comprehensive.
Disadvantages of ERC-20 tokens
Poor scalability h4>
This is a common problem with many cryptocurrency networks, and Ethereum is not immune to it. In its current form, it doesn't scale well. Sending transactions during peak periods incurs high fees and long delays. If ERC-20 tokens are used and cause network congestion, their availability will also be affected.
This is not a problem unique to Ethereum, but a trade-off that all secure distributed systems must make. The community plans to solve these problems after migrating to Ethereum 2.0 and implement upgrades such as Ethereum Plasma and Ethereum Casper.
Please read "Blockchain Scalability: Sidechains and Payment Channels" to learn more about scalability issues.
Fraud
While there is nothing wrong with the technology itself, in some ways the ease of issuing tokens can be a disadvantage. Simple ERC-20 tokens are easy to create, meaning anyone can do it, but with mixed intentions.
Therefore, you must invest carefully. There are many pyramid schemes and Ponzi schemes disguised as blockchain projects. You must do your own research before investing to confirm whether the investment opportunity is legitimate.
What are the differences between ERC-20, ERC-1155, ERC-223 and ERC-721?
ERC-20 is the first (and by far the most popular) Ethereum token standard, but it is not the only one. Over the years, many other standards have been developed. Most of them are improved standards of ERC-20, others try to achieve completely different goals.
A few uncommon standards apply to non-fungible tokens (NFTs). In some cases, unique tokens with different properties can make you the beneficiary. If you want to tokenize unique artwork, in-game assets, etc., one of these types of contracts may be more attractive.
For example, the ERC-721 standard is used in the very popular CryptoKitties DApp. This contract provides an API for users to mint their own non-fungible tokens and encode metadata (images, descriptions, etc.).
The ERC-1155 standard can be seen as an improvement on ERC-721 and ERC-20. It supports both fungible and non-fungible token standards in a single contract.
Other options such as ERC-223 or ERC-621 are designed to improve usability. The former implements protection measures to prevent accidental transfers of tokens. The latter provides additional functionality for increasing or decreasing the token supply.
To learn more about NFTs, please read the Guide to CryptoCollectibles and Non-Fungible Tokens (NFTs).
Summary
The ERC-20 standard has been the dominant player in the crypto-asset space for many years. The reasons are obvious: the standard is relatively simple and anyone can deploy simple contracts to suit various needs (utility tokens, stablecoins, etc.). Nonetheless, ERC-20 does lack some features of other standards, but it remains to be seen whether other contract types can take its place.