IARD Solutions

An In-Depth Explanation of the ERC-20 Standard

In the rapidly evolving world of blockchain technology and cryptocurrencies, understanding the underlying standards and protocols is crucial. The most famous one that anyone that has interacted with the blockchain ecosystem is probably the ERC-20 standard. This article aims to provide an in-depth explanation of the ERC-20 standard, its functionality, and its importance in the Ethereum network, other EVM blockchains and beyond.

1. What is ERC-20

ERC-20 is a technical standard interface used for smart contracts on the Ethereum blockchain for implementing tokens, which are most of the cryptocurrencies you know. It was proposed in November 2015 by Ethereum developers and founding members Fabian Vogelsteller and Vitalik Buterin. ERC stands for Ethereum Request for Comment, and 20 is the unique proposal ID number. You can find the original proposal here: “ERC-20: Token Standard

Today, and since the launch of this standard, the ERC-20 has been the principal way to create and use fungible tokens. Others have imagined different standard since then, such as the ERC-721 which is what’s called NFTs or the more recent “ERC-404” which is a mix of ERC-20 and ERC-721 to put it in a nutshell. On that note, we did an interview of the developer at the origin of this idea, Serec Thunderson, in another article.

 

2. Understanding the ERC-20 functions

The first thing to understand, and it’s valid for any ERC, is that it only describes what the implementation should at least possess. It describes mainly a list of functions and events, their inputs and outputs, but it is up to each project to implement it as they see fit. That’s why you should always either read the code yourself or assert that it has been audited by competent people before using any ERC-20 or any other contracts.

Back to the main subject, the ERC-20 standard outlines six mandatory functions and three optional ones that every ERC-20 token should implement. The mandatory functions are:

  • totalSupply(): This function returns the total supply of tokens available in circulation.

  • balanceOf(address _owner): This function returns the account balance of another address _owner.

  • transfer(address _to, uint256 _value): This function sends _value amount of tokens to the address _to and must fire the Transfer event. The function should throw an error if the message caller’s account balance does not have enough tokens to spend.

  • transferFrom(address _from, address _to, uint256 _value): This function transfers _value amount of tokens from address _from to address _to and must fire the Transfer event. The function should throw an error unless the _from account has deliberately authorized the sender of the message via some mechanism.

  • approve(address _spender, uint256 _value): This function allows _spender to withdraw from your account multiple times, up to the _value amount. If this function is called again, it overwrites the current allowance with _value.

  • allowance(address _owner, address _spender): This function returns the amount which _spender is still allowed to withdraw from _owner.

The optional functions include:

  • name(): This function returns the name of the token, improving usability. However, interfaces and other contracts must not expect these values to be present.

  • symbol(): This function returns the symbol of the token, improving usability. However, interfaces and other contracts must not expect these values to be present.

  • decimals(): This function returns the number of decimals the token uses, improving usability. However, interfaces and other contracts must not expect these values to be present.

ERC-20 tokens should also implement two events:

  1. Transfer: This event must trigger when tokens are transferred, including zero value transfers.

  2. Approval: This event must trigger on any successful call to approve(address _spender, uint256 _value).

In most of the implementation, the balance of every user will be stored in a private variable, meaning its values can only be edited by the functions of this same contract, that map every Ethereum address to an integer representing the amount of tokens owned by this particular address and updated or read by the functions presented before. And that’s it. The core of most ERC-20 tokens is just a simple data store, which is really different from the native tokens of most if not all blockchains such as Ethereum itself.

You can find different popular implementations of the ERC-20 standard on the web, such as the OpenZeppelin’s implementation, if you want to take a look at actual code. You can also check out our blog post on beginners resources to learn Solidity.

 

3. Conclusion

The ERC-20 standard plays a pivotal role in the widespread adoption and use of tokens within the Ethereum network. By providing a standard, developers can accurately predict how new tokens will function within the larger Ethereum system. This allows for greater interoperability between tokens and ensures a uniform user experience when interacting with different DApps. Moreover, the ERC-20 standard has facilitated the creation of a thriving token economy, enabling projects to raise funds through Initial Coin Offerings (ICOs) and Token Generation Events (TGEs).

The ERC-20 standard has become an integral part of the Ethereum network, providing a standardized approach to creating and implementing tokens. By understanding the functions and importance of the ERC-20 standard, one can better navigate the complex world of blockchain technology and cryptocurrencies. As the blockchain ecosystem continues to evolve, standards like ERC-20 will likely continue to play a crucial role in shaping its future and being able to understand them will allow you to make the most of it and avoid pitfalls.