Introduction
Ethereum was created by Vitalik Buterin in 2014 as an open-source platform for launching decentralized applications (DApps). Buterin's primary motivation for developing this new blockchain was the lack of flexibility in the Bitcoin protocol.
Since then, the Ethereum blockchain has attracted a large number of developers, businesses, and entrepreneurs, giving rise to an emerging industry centered around user-friendly smart contracts and distributed applications.
In this article, we will explore the ERC-20 standard, an important framework for creating tokens. While it is specific to the Ethereum network, it has also inspired standards on other blockchains.
What is the ERC-20 Standard?
In Ethereum, ERC stands for “Ethereum Request for Comments.” These technical documents outline the programming standards for Ethereum. It is important to note that this is different from Ethereum Improvement Proposals (EIPs), which are akin to Bitcoin's BIPs and relate to suggestions for improvements to the protocol itself. The purpose of an ERC is to establish a protocol that facilitates interaction between applications and contracts.
The ERC-20 standard was jointly developed by Vitalik Buterin and Fabian Vogelsteller in 2015. It provides a relatively simple format for tokens based on Ethereum. Developers can follow this outline to build on existing infrastructure without the need to redevelop.
Once new ERC-20 tokens are created, they automatically achieve interoperability with services and software that support the ERC-20 standard, such as software wallets, hardware wallets, and trading platforms.
It is worth noting that the ERC-20 standard later evolved into an EIP, specifically EIP-20. Although years have passed since the initial proposal, the name "ERC-20" has been retained.
Overview of Ethereum Tokens
Unlike ETH (Ethereum's native cryptocurrency), ERC-20 tokens are not stored in accounts but exist solely within contracts, similar to an independent database. The ERC-20 standard defines the rules for tokens, including name, symbol, and divisibility, while maintaining a mapping of user balances against Ethereum addresses.
To transfer tokens, users need to send a transaction to the smart contract, requesting that a portion of the balance be allocated to other addresses. For example, if Alice wants to send 5,000 tokens to Bob, she would call a function in the corresponding smart contract to execute this operation.
Her call may appear to be a regular Ethereum transaction, but this transaction actually pays 0 ETH to the token contract. This call is included in other fields of the transaction, clearly indicating Alice's intent—in this case, to transfer tokens to Bob.
Although no Ether needs to be sent, Alice still has to pay a fee to have the transaction included in a block. If she does not have ETH, she must pre-fund her account with some ETH before transferring tokens.
Here is a real example from Etherscan that shows someone calling a BUSD contract. You will see that the tokens were successfully transferred and a fee was paid, even though the value field of the transaction indicates that 0 ETH was sent.
How Are ERC-20 Tokens Created?
According to the ERC-20 standard, your contract needs to implement six mandatory functions: totalSupply, balanceOf, transfer, transferFrom, approve, and allowance. Additionally, you may choose to add some optional functions such as name, symbol, and decimal. The function names typically reflect their purposes intuitively, but if you’re unsure, don’t worry; we will explain each function one by one.
Below are examples of these functions written in Solidity, the programming language specific to Ethereum.
totalSupply
function totalSupply() public view returns (uint256)
When this function is called, users will receive the total supply of tokens held by the contract.
balanceOf
function balanceOf(address _owner) public view returns (uint256 balance)
Unlike totalSupply, the balanceOf function requires an address as a parameter. When called, it returns the token balance of that address. Note that account information on the Ethereum network is public; as long as you know an address, you can query any user's token balance.
transfer
function transfer(address _to, uint256 _value) public returns (bool success)
The transfer function allows users to transfer tokens to one another. Users must provide the recipient's address and the amount to be transferred. When called, the transfer function will trigger an event (in this case, a "Transfer" event) to notify the blockchain about the function call.
transferFrom
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success)
The transferFrom function acts as a convenient alternative to transfer, enhancing the programmability of decentralized applications. Its function is similar to transfer, but it can be used to transfer tokens that do not belong to the user calling the contract. In other words, you can authorize others or another contract to transfer funds on your behalf. For example, if you do not want to manually make daily, weekly, or monthly payments for a subscription service, you can have the program handle it for you.
The event triggered by this function is the same as that for the transfer function.
approve
function approve(address _spender, uint256 _value) public returns (bool success)
From a programming perspective, the approve function is quite useful as it can limit the amount of tokens the smart contract can withdraw from a balance. Without this mechanism, contracts could become ineffective or be exploited, leading to the theft of funds. For instance, suppose you want to set up weekly recurring payments for a streaming DApp but do not want to create transactions manually.
If you hold a large number of tokens while the weekly subscription fee is low, you can set a withdrawal limit using approve. For example, if your subscription costs 1 token per week but you approve a limit of 20 tokens, the DApp can withdraw a maximum of 20 tokens over five months. If an error occurs and the DApp attempts to withdraw the entire balance, you would only lose 20 tokens. While this loss is not insignificant, it is certainly better than losing all your assets.
After calling this function, approve will trigger an approval event and write the relevant data to the blockchain.
allowance
function allowance(address _owner, address _spender) public view returns (uint256 remaining)
The allowance function can be used in conjunction with approve. If you have granted token management permissions to a contract, you can use this function to check the balance of tokens available for withdrawal. For example, if the subscription service has used 12 of the 20 approved tokens, calling the allowance function would return 8 tokens.
Other Optional Functions
The functions mentioned above are mandatory. In contrast, name, symbol, and decimal are optional functions, but they enhance the completeness of the ERC-20 standard. These functions are used to add a human-readable name, set a symbol (such as ETH, BTC, BNB), and specify the number of decimal places the token can be divided into. Generally, tokens used as currency are easier to divide than those representing asset ownership, making them more flexible.
What Functions Does ERC-20 Have?
The cumulative set of all the previously mentioned functions forms a complete ERC-20 contract. Through these functions, we can query the total supply of tokens, check balances, transfer funds, and authorize other decentralized applications (DApps) to manage tokens on our behalf.
One of the significant advantages of ERC-20 tokens is their flexibility. The established standard does not restrict developers; parties can add additional functions and set specific parameters based on their needs.
Stablecoins
Stablecoins are tokens pegged to fiat currencies and typically use the ERC-20 standard. The BUSD contract mentioned earlier is a typical example, and many stablecoins adopt this format.
For stablecoins backed by mainstream fiat currencies, the issuer can hold reserves in euros, dollars, etc., and issue a token for each unit of reserve. This means that if they store $10,000, the issuer can create 10,000 tokens, with each token redeemable for $1.
From a technical standpoint, implementing this on Ethereum is straightforward. The issuer simply launches a contract with 10,000 tokens and distributes them to users, promising that they can later redeem the tokens for a certain proportion of fiat currency.
Users can utilize these tokens for various purposes, including purchasing goods and services and using them in DApps. Additionally, they can request immediate redemption of these tokens from the issuer. In this case, the issuer may choose to burn the returned tokens (rendering them invalid) and withdraw an equivalent amount of fiat currency from the reserves.
Although managing these contracts is relatively simple, launching a stablecoin still requires consideration of numerous external factors (such as logistics and compliance), which often demands significant effort.
Security Tokens
Security tokens are similar to stablecoins and can actually be identical at the contract level since they operate in the same way. The primary difference lies in the issuer: security tokens represent securities such as stocks, bonds, or physical assets. Typically, these tokens grant holders a stake in a company or commodity.
Utility Tokens
Utility tokens are currently the most common type of token. Unlike the previous two types, utility tokens are not backed by actual assets. If shares in an airline are considered asset-backed tokens, utility tokens are akin to frequent flyer miles: they have certain functionalities but no external value. Utility tokens can serve various purposes, such as in-game currencies, fuel for decentralized applications, or loyalty points.
Can You Participate in ERC-20 Token Mining?
You can mine Ether (ETH), but the tokens themselves cannot be mined—creating new tokens is referred to as "minting." After a contract goes live, developers allocate the token supply according to their plans and roadmaps, typically through methods like Initial Coin Offerings (ICOs), Initial Exchange Offerings (IEOs), or Security Token Offerings (STOs). You may encounter various versions of these acronyms, but their concepts are fundamentally similar. Investors send Ether to the contract address in exchange for new tokens as a reward. The funds raised are used to support the future development of the project.
The distribution of tokens is not necessarily automated. Many crowdfunding campaigns allow users to make payments using various cryptocurrencies (such as BNB, BTC, ETH, and USDT) and allocate the corresponding tokens to the addresses provided by the users.
Advantages and Disadvantages of ERC-20 Tokens
Advantages of ERC-20 Tokens
Interchangeability
ERC-20 tokens possess excellent interchangeability, allowing all token units to be exchanged with one another. Regardless of which specific token you hold, their functionalities are consistent, similar to cash or gold. If you envision these tokens evolving into a form of currency, this is undoubtedly an ideal feature. Tokens with distinctive characteristics may lose their interchangeability, leading to some tokens being valued lower or higher than their peers, ultimately undermining their intended purpose.
Flexibility
As previously mentioned, ERC-20 tokens offer a high degree of customization, allowing them to be tailored to the needs of different applications. For instance, they can serve as in-game currencies, loyalty points for applications, digital collectibles, or even represent ownership of artwork and property.
Popularity
ERC-20 enjoys widespread popularity in the cryptocurrency space, and its blueprint is quite convincing. Many trading platforms, wallets, and smart contracts are already compatible with various newly launched tokens. Additionally, there is ample support and documentation available for developers.
Disadvantages of ERC-20 Tokens
Scalability Issues
Scalability is a common challenge faced by many cryptocurrency networks, and Ethereum is no exception. The current network structure may incur high fees and long delays when processing transactions during peak times. If the use of ERC-20 tokens leads to network congestion, its usability may also be affected.
This is not a problem unique to Ethereum; it is a trade-off that all secure distributed systems must contend with. The community plans to address these issues following the migration to Ethereum 2.0, implementing upgrades such as Ethereum Plasma and Ethereum Casper.
Fraud Risks
Although the technology itself is sound, the ease of issuing tokens can be a double-edged sword in some respects. Simple ERC-20 tokens can be easily created, meaning anyone can engage in this process, but the intent behind their creation may vary significantly.
As a result, investors need to exercise caution. Many pyramid schemes and Ponzi schemes disguise themselves as blockchain projects, so thorough research is essential to verify the legitimacy of investment opportunities before committing funds.
What Are the Differences Between ERC-20, ERC-1155, ERC-223, and ERC-721?
ERC-20 is the first and most popular Ethereum token standard, but it is not the only one. Over the years, other standards have emerged, many of which improve upon ERC-20, while others pursue entirely different goals.
Some less common standards apply to non-fungible tokens (NFTs). In certain cases, unique tokens with different attributes can provide benefits. When it comes to tokenizing unique assets such as artworks or in-game items, some contracts may be more appealing. For example, the ERC-721 standard is used by the popular CryptoKitties DApp. This contract provides users with an API to mint exclusive non-fungible tokens and encode metadata (such as images and descriptions).
The ERC-1155 standard can be seen as an improvement over both ERC-721 and ERC-20, allowing for the simultaneous support of fungible and non-fungible tokens within a single contract.
Other options, such as ERC-223 or ERC-621, aim to enhance usability. ERC-223 implements safeguards to prevent accidental token transfers, while ERC-621 provides additional functionality to increase or decrease the token supply.
For more information about NFTs, please refer to the "Guide to Crypto Collectibles and Non-Fungible Tokens (NFTs)."
Conclusion
Over the years, the ERC-20 standard has dominated the realm of crypto assets for obvious reasons: this standard is relatively simple, allowing anyone to deploy contracts easily to meet various needs (such as utility tokens, stablecoins, etc.). However, while ERC-20 may lack some functionalities present in other standards, it remains to be seen whether it will be supplanted by other contract types in the future.
Risk Warning
While the cryptocurrency market offers significant growth potential and innovation opportunities, it also carries a high level of market risk and price volatility. The value of crypto assets can fluctuate dramatically in a short period, potentially leading to substantial financial losses for investors. Additionally, the cryptocurrency market faces multiple risk factors, including technical risks, legal and regulatory uncertainties, cybersecurity threats, and market manipulation. We strongly advise users to conduct thorough research and due diligence before making any investment decisions and to consult professional financial advisors. All investment decisions are made at the user’s own risk. Thank you for your trust and support of Venkate!
Building The Future of Crypto Exchange
Where Meet a Confluence of Inspiration and Innovation
Venkate Exchange is an innovative cryptocurrency trading platform, drawing its name and inspiration from Venkateswara—a deity symbolizing wealth and prosperity in Indian mythology.
Comments
0 comments
Article is closed for comments.