Let's talk about ERC-20 tokens

·

4 min read

What Are Tokens?

Tokens have different meanings, but in the blockchain world- the one this article is focused on, a token refers to a virtual currency. Tokens can be used to represent a variety of things such as reward systems like points in an online game or points for completing a course, financial assets, fiat currencies and many more.

Tokens can be bought, sold, traded and some have even been used to raise funds for a variety of initiatives.

In this article, we’ll discuss the ERC-20 standard and ERC-20 tokens.

What Is The ERC-20 Standard?

One of the most popular blockchain networks where tokens live on is the Ethereum network. As tokens can be created by anyone interested in creating it, a standard of some kind is needed. Tokens that live on the Ethereum network are expected to follow a particular standard known as the ERC-20 standard.

The ERC-20 standard refers to a technical standard that lays down a couple of rules such as how tokens can be transferred, how transactions are approved, and the total supply of tokens. The ERC-20 standard arose from a 2015 proposal that was merged into the Ethereum protocol via an Ethereum Improvement Proposal (IEP-20).

This standard specifies 6 basic coding functions that should be followed when building a token that will live on the Ethereum network. When implementing an ERC-20 token, these are the basic functions that should be added.

  • Total supply
  • Balance
  • Transfer
  • Transfer from
  • Approve
  • Allowance

In addition to the 6 functions stated above, you can also include name, symbol, and decimal functions.

This means that an ERC-20 compliant implementation should be able to transfer tokens from one account to another, get the balance of tokens in a given account, get the total supply of tokens available on that network, approve if an amount of token from a given account can be spent by a third-party account, and grant approval or agree to automated transactions.

Let’s see what they look like when written in code.

totalSupply

function totalSupply() public view returns (uint256)

When called, it returns the total supply of tokens held in this contract.

balanceOf

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

This function takes in an address parameter and returns the number of tokens held in that particular address.

transfer

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

This function takes in address _to and an unsigned integer parameter which refers to the address where tokens will be transferred to, and the number of tokens to be transferred. When called, the specified number of tokens are transferred from the caller’s balance to the specified address in the function.

transferFrom

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

Just like the transfer function, this function is used to transfer money from one account to another. However, the difference here is that the caller does not necessarily need to be the owner of the tokens. Another person can be authorized to transfer funds from a contract on behalf of the owner. It takes as parameters, the address to transfer from, the address to transfer to, and the number of tokens to be transferred.

approve

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

This function, when called approves a specified number of tokens to be withdrawn from your balance. It takes in the address of where the tokens will be sent, and the maximum number of tokens that can be withdrawn from your balance from that address.

allowance

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

This function works well with the approve function. It can be used to check how many tokens a contract can still withdraw from your balance. It also helps you keep track of your tokens in relation to another contract address.

The functions stated above are compulsory while functions such as name, symbol, and decimal are optional and can be used based on the smart contract creator’s discretion.

What Then Are ERC-20 Tokens?

Tokens that follow the set of rules laid down in the ERC-20 standard are known as ERC-20 tokens. They are sets of 'fungible' digital tokens that live on the Ethereum network. Fungible here means that every token in a particular set cannot be differentiated or told apart from another token in the same set. Every token in the same set have the same value and can be used interchangeably.

Following the ERC-20 standard ensures that different tokens on the Ethereum system perform in a uniform manner and have functionalities that are predictable.

Some popular digital currencies that built following the ERC-20 standard includes: Chainlink (LINK) Tether (USDT) Maker (MKR) Basic Attention Token (BAT) Shiba Inu (SHIB)

Conclusion

Following a standard rule while creating anything always comes with advantages, and the ERC-20 is not left out. Tokens created following the ERC-20 standard are known to have predictable features and as such can perform in a uniform manner when compared to different other tokens on the Ethereum system. While ERC-20 may not be the only standard for creating tokens, it sure is a great one to follow.