What is ERC-20 Token?

Aman Agarwal
Enlear Academy
Published in
5 min readJan 10, 2022

--

In the Ethereum world, ERC-XXX or EIP-XXXX phrases often come up, but for people new to the Ethereum world, this looks quite cryptic.

What is EIP?

Ethereum Improvement Proposals (EIPs) are standards specifying potential new features or processes for Ethereum. EIPs contain technical specifications for the proposed changes and act as the “source of truth” for the community. Network upgrades and application standards for Ethereum are discussed and developed through the EIP process.

What is ERC?

ERC is an abbreviation for Ethereum request for comments. These are technical publications created for the Ethereum community by Ethereum developers. Each of these documents includes a set of rules that must be followed to build tokens for the Ethereum ecosystem. To develop guidelines for the Ethereum platform.

How did EIP become a new ERC?

A developer uploads an Ethereum Improvement Proposal to establish standards for the Ethereum platform (EIP). Protocol specifications and smart contract standards are included in each EIP. Once an EIP has been authorized and confirmed by a committee, it becomes an ERC.

So we are here to know about EIP-20, which is now in the category of ERC.

What Is ERC-20?

ERC-20 is one of the most important Ethereum coins. ERC-20 has emerged as the technical standard; it is utilized for token implementation in all smart contracts on the Ethereum blockchain and specifies a set of rules that all Ethereum-based tokens must follow.
ERC-20 is comparable to bitcoin, Litecoin, and any other cryptocurrency in certain ways; ERC-20 tokens are blockchain-based assets with value that can be transmitted and received. The key distinction is that ERC-20 tokens are issued on the Ethereum network rather than on their blockchain.

ERC-20 Protocols

The interface of the ERC20 standard as defined in the EIP, there must be the following 8 functionality to be included in the Smart contract to stand on the ERC-20 standard.

FUNCTIONS

  1. totalSupply()
  2. balanceOf(account)
  3. transfer(recipient, amount)
  4. allowance(owner, spender)
  5. approve(spender, amount)
  6. transferFrom(sender, recipient, amount)

EVENTS

7. Transfer(from, to, value)

8. Approval(owner, spender, value)

It might be self-explanatory, but we will tear this apart and see its exact functionalities.

Functions

1. totalSupply

Returns the total token supply.

function totalSupply() public view returns (uint256)

2. balanceOf

Returns the account balance of another account with address _owner.

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

3. transfer

Transfers _value amount of tokens to address _to, and MUST fire the Transfer event. The function SHOULD throw if the message caller’s account balance does not have enough tokens to spend.

NOTE: Transfers of 0 values MUST be treated as normal transfers and fire the Transfer event.

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

4. allowance

Returns the amount which _spender is still allowed to withdraw from _owner.

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

5. approve

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.

NOTE: To prevent attack vectors like the one described here and discussed here, clients SHOULD make sure to create user interfaces in such a way that they set the allowance first to 0 before setting it to another value for the same spender. THOUGH The contract itself shouldn’t enforce it, to allow backward compatibility with contracts deployed before

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

6. transferFrom

Transfers _value amount of tokens from address _from to address _to, and MUST fire the Transfer event.

The transferFrom the method is used to withdraw workflow, allowing contracts to transfer tokens on your behalf. This can be used to allow a contract to transfer tokens on your behalf and/or to charge fees in sub-currencies. The function SHOULD throw unless the _from account has deliberately authorized the sender of the message via some mechanism.

NOTE: Transfers of 0 values MUST be treated as normal transfers and fire the Transfer event.

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

Events

7. Transfer

MUST trigger when tokens are transferred, including zero value transfers.

A token contract that creates new tokens SHOULD trigger a Transfer event with the _from address set to 0x0 when tokens are created.

event Transfer(address indexed _from, address indexed _to, uint256 _value)

8. Approval

MUST trigger on any successful call to approve(address _spender, uint256 _value).

event Approval(address indexed _owner, address indexed _spender, uint256 _value)

Some optional but helping function can be …

This method can improve usability, but interfaces and other contracts MUST NOT expect these values to be present.

name

Returns the name of the token — e.g. "MyToken".

function name() public view returns (string)

symbol

Returns the symbol of the token. E.g. “HIX”.

function symbol() public view returns (string)

decimals

Returns the number of decimals the token uses — e.g. 8, means to divide the token amount by 100000000 to get its user representation.

function decimals() public view returns (uint8)

Implementation

There are already plenty of ERC20-compliant tokens deployed on the Ethereum network. Various teams have written different implementations that have different trade-offs: from gas saving to improved security.

Example implementations are available at

Conclusion

ERC-20 token is for scaling our Smart contract token, it is not necessary to only implement ERC-20; we can look for many EIPs that are suitable for the contract according to our needs and demands for using that token. So soon, we will be made our hands in the dirt with ERC-20 smart contracts.

You can support me and my content by buying a coffee ☕ here.

Follow me on Twitter and LinkedIn.

--

--