Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

solidity
ethereum
communitycreator

What is an ERC20 token?

Dario Vincenzo Tarantini

In Ethereum and other EVM blockchains, an ERC20 token is a smart contract that implements a robust standard to create fungible tokens.

Note: The standard only defines a set of functions and events that must be implemented in our contract; the implementation itself belongs to us.

The history and importance of ERC20

Back in 2015, there was the need to virtually represent something inside the blockchain. With EIP-20 (Ethereum Improvement Proposal), they solved the problem by creating a common API interface to build a fungible token.

These tokens can represent anything, from USD pegged coins (such as USDT) to lottery tickets. Initially, the tokens were widely used to create ICOInitial Coin Offering and crowdfunding companies. Today, these tokens are commonly traded via peer-to-peer trading, inside AMM, and traditional markets. There is no doubt that ERC20 tokens took a significant role in the growth of cryptocurrencies.

ERC20 tokens

An ERC20 token must implement the following functions:

  • balanceOf: Provides the balance of a specific address.
  • transfer: Provides a way to transfer a number of tokens to an address.
  • transferFrom: Is the same as transfer, but anyone is allowed to transfer a number of tokens from one address to another.
  • _approve: Allows the spender to withdraw a number of tokens from a specific account.
  • allowance: Returns a set number of tokens from a spender to the owner.

ERC20 tokens should also implement two events: Transfer and Approval, triggered on a transfer or approvals of the spender.

Example

We can use the OpenZeppelin library to make a simple ERC20 token, which provides a safe and audited set of libraries to build ERC-20 tokens.

In Remix IDE, we can just use the contract below to build one:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.2;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract MyToken is ERC20 {
    constructor() ERC20("MyToken", "MTK") {}
}

In this simple example, we import this contract and use it to extend our contract with the is keyword.

RELATED TAGS

solidity
ethereum
communitycreator

CONTRIBUTOR

Dario Vincenzo Tarantini
RELATED COURSES

View all Courses

Keep Exploring