DEV Community

Cover image for ERC-20 Tokens
AbhayPatel98
AbhayPatel98

Posted on

ERC-20 Tokens

An ERC-20 token is a representation of some sort of asset on the Ethereum network. These could be anything:

shares in a company
reward system points
voting rights
cryptocurrency
lottery tickets
on-chain Chuck E Cheese tokens
anything you can think of!
This is what has made Ethereum a popular choice for many different use cases across industries - anyone can tokenize any asset.

Importance of the ERC-20 Token Standard
A key point to understand here is that ERC-20 is a technical standard! đź’ˇ

The main use of the ERC-20 standard is to increase compatibility of the ecosystem. Exchanges like Uniswap are then able to build incredibly powerful applications because they create infrastructure that supports the ERC-20 interface; this then triggers developers who use the ERC-20 standard to develop, instant compatibility with Uniswap and many other dApps!

ERC-20 Token Smart Contract
At the base level, an ERC-20 token smart contract simply uses a mapping to keep track of fungible tokens: any one token is exactly equal to any other token; no tokens have special rights or behavior associated with them.

ERC-20 Token Interface
As we covered above, ERC-20 defines a common interface so that any application can use them in a standard way.

This simplifies and eases developers’ tasks, because they can proceed with their work, knowing that each and every new project won’t need to be redone every time a new token is released, as long as the token follows the rules.

The interface consists of a number of functions that must be present in every implementation of the standard, as well as some optional.

An ERC-20-compliant token contract must provide at least the following:

name, symbol, and decimals are all optional fields
totalSupply defines the current circulating supply of the tokens
balanceOf will return the balance for a particular user
transfer which is the bread and butter, transfer from one account to another
approve, transferFrom and allowance are methods for other contracts moving your funds

Image description

ERC-20 Data Structures
There are two important data structures used by the ERC-20 token standard that we should review:

balances: mapping of token balances, by owner. Each transfer is a deduction from one balance and an addition to another balance.
allowances: mapping of allowances/delegate spending. This is a nested mapping in which the primary key is the address of the token owner which maps to a spender address and amount delegated to spend.

Oldest comments (0)