The Wayback Machine - https://web.archive.org/web/20240731115922/https://www.geeksforgeeks.org/erc20-vs-erc721-in-ethereum/
Open In App

ERC20 vs ERC721 in Ethereum

Last Updated : 27 Feb, 2023
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report

ERC or Ethereum Request for Comments is simply a guideline or a template that all Ethereum-based tokens should follow. Some rules are laid down by programmers in these templates or documents that Ethereum-based tokens must comply with. Functionalities such as transferring tokens from one account to another, to get the current token balance of an account, and the total supply of the token available on the network. ERC-20 and ERC-721 tokens are the initial types of ERC token standards that serve an important role in defining the functionality of the Ethereum ecosystem.

The following topics will be discussed here:

  1. How Are Tokens Created?
  2. Introduction To ERC-20 Token.
  3. Introduction To ERC-721 Token.
  4. ERC-20 Token vs ERC-721 Token.

Let’s start discussing each of these topics in detail.

How are Tokens Created?

Tokens exist on the Ethereum platform and that in itself consists of a blockchain that is capable of storing transactions and a virtual machine that is capable of running smart contracts. It is again important to note that the tokens live on the Ethereum blockchain. They aren’t independent and rely on Ethereum’s blockchain and platform. The native currency on the Ethereum network is Ether but it can also support other tokens and these can work like currencies that can represent shares of a company, gold certificates, and so on.

  • Tokens are created by smart contracts which are not only responsible for creating tokens but also for handling transactions and keeping track of balances. 
  • To get some tokens, one has to send some Ether to the Smart contract which will then give some tokens.
Product of Tokens

 

  • Once a smart contract is deployed, it can’t be changed anymore, so if one makes a mistake, nothing can be done about it which could be quite catastrophic. 
  • Imagine a bug inside the contract’s code that causes people to lose their tokens or get the tokens stolen. 
  • There’s also a problem with interoperability. Each token contract can be completely different from the other so if one wants the token to be available on an exchange, the exchange has to write a custom code that can talk to the contract and allow people to trade. 
  • The same thing goes for wallet providers. Supporting hundreds of tokens would be very complex and time-consuming.  
  • So instead, the community proposed a standard called ERC-20 which stands for  “Ethereum Requests for Comments” and 20 is just a number they assigned to a proposal that would create some structure in the world of tokens. 

Introduction To ERC-20 Token

ERC-20 is one of the most significant standards for Ethereum tokens. ERC-20 was first proposed in 2015 and integrated into the Ethereum blockchain in 2017. It is similar to bitcoin, Litecoin, etc in many ways. 

  • Token represents digital assets such as coupons or even real-life stuff. 
  • They can be sold, bought, and traded and have values that can be sent or received. 
  • Well-known currencies such as Basic Access Token (BAT), Augur (REP), Maker (MKR), and the OMG network are ERC-20 standards. 
  • The tokens have the same values and they are replaceable with another copy of the token. This makes it fungible i.e mutable or changeable or not unique. 

Before there was the ERC-20 standard, everyone who wanted to create a token had to reinvent the wheel which meant that each token contract was slightly different and that exchanges and wallets had to write custom code to support your token. With ERC-20 this code has to be implemented just once. That’s why exchanges can add new tokens so quickly. It’s important to keep in mind that there is no “central registry” for token contracts, which means that the uniqueness of a particular token name or symbol is not guaranteed.

ER-20 is a representation of some sort of asset on the Ethereum blockchain and a token is an ERC-20 token can represent a lot. It could represent a currency (cryptocurrency to be more clear) or any other kind of asset.

Functions of components in ERC-20 Tokens are mentioned in the below. These functions are defined in the IERC20 (Interface of the ERC20 standard ) defined in the EIP:

  • transfer(): Takes a certain amount of tokens from the total supply and transfers them to a user.
  • transferFrom(): Tokens is transferred between any two users who have them.
  • approve(): verifies that your contract can give a certain amount of tokens to a user.
  • allowance(): Same as approval, except the fact that it checks that a user has enough balance to send a certain amount of tokens to someone else.
  • balanceOf(): returns how many tokens a given address has.
  • totalSupply(): Defines the total number of tokens. When this limit is reached, the smart contract refuses to create any more tokens. 

These code functions are important when it comes to user/token implementation, mainly in making transfers, granting approvals and determining the number of tokens in circulation, storing and returning balances.

Drawbacks of the ERC-20:

ERC-20 is only a guideline and people are free to implement the required functions however they like. That has led to some interesting problems.

  • For instance, to buy some tokens, one has to send some Ether to the token contract but some people tried sending their ERC-20 tokens instead. 
  • If the contract was not designed with this in mind, it will result in your tokens being lost. 
  • In order to resolve this, the company is trying to improve the ERC-20 standards with the ERC-223 standard. 
  • This warns token creators about these risks and offers some workarounds.

Example of ERC-20 Token :- 

Solidity




// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.8.0 <0.9.0; 
import "@openzeppelin/contracts@4.8.1/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts@4.8.1/access/Ownable.sol";
/// @title A contract for demonstrate ERC-20 Token
/// @author Jitendra Kumar
/// @notice For now, this contract just show how to create an ERC-20 Token
 
contract GFGToken is ERC20, Ownable {
 
    constructor () ERC20("GFGToken", "GFG") {
        _mint(msg.sender, 1000 * (10 ** uint256(decimals())));
    }
     
   function decimals() public view virtual override returns (uint8) {
        return 8;
    }
}


Introduction To ERC-721 Token

ERC-721 is a standard “non-fungible” token. A non-fungible token is the type of token that is unique. These are cryptographic assets on a blockchain that has a unique code and metadata differentiating them from one another. The ERC-721 standard non-fungible tokens can be seen in blockchain-based games where each asset is unique and players can trade it and sell or buy items with it. ERC-721 is basically a template or a guideline that other developers agree to follow. It is a widely used standard. Being a widely used standard also means being compatible with a  wide range of applications.

  • They are non-fungible tokens. 
  • ERC721 is more of an Ethereum Improvement Proposal or EIP.
  • One of the most important components is the flexibility for using them in all the exchanges.
  • The main characteristic of ERC-721 tokens is that each one is unique.
  • The value of ERC-721 tokens depends on the uniqueness and rarity of the asset.
  • One NFT cannot replace another, due to differences in values.
  • We can emulate rare, collectible items with these Ethereum tokens.

Components in ERC-721 token:

The ERC721 has the following important functions:

  • name()
  • symbol()
  • tokenURI()
  • onERC721Received()
  • totalSupply()
  • balanceOf()
  • ownerOf()
  • safeTransferFrom()
  • transferFrom()
  • approve()
  • setApprovalForAll()
  • getApproved()
  • isApprovedForAll()
  • takeOwnership()
  • tokenMetadata()
  • tokenByIndex()
  • tokenOfOwnerByIndex()
  • supportsInterface()

Fungible means interchangeable and replaceable. Bitcoin is fungible because any Bitcoin can replace any other Bitcoin. Each NFT, on the other hand, is completely unique. One NFT cannot replace another, there an NFT is non-fungible. One of the examples that use the ERC-721 non-fungible tokens standard is the Cryptokitties game which is basically a game developed on the blockchain which allows users to sell, buy and breed virtual cats. The assets bought with a non-fungible token are unique and only belong to the owner. It can’t be traded. The ERC721 standard tokens are created the same way as other kinds of tokens and can be created as many as the user wishes but the only difference is that the tokens have a unique value and unique metadata.

Example of ERC-721 Token:

Solidity




// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.8.6 <0.9.0; 
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
/// @title A contract for demonstrate ERC-721 Token
/// @author Jitendra Kumar
/// @notice For now, this contract just show how to create an ERC-721 Token
contract GFGToken is ERC721, Ownable, ERC721URIStorage {
    using Counters for Counters.Counter;
    Counters.Counter private _tokenCountCounter;
    constructor() ERC721("GFGToken", "GFG") {}
     
    //mint the NFT token along with the TokenURI using Owner Address
    function safeMint(string memory _tokenURI) public onlyOwner {
        uint256 tokenCount = _tokenCountCounter.current();
        _tokenCountCounter.increment();
        _safeMint(msg.sender, tokenCount);
        _setTokenURI(tokenCount, _tokenURI);
    }
    //burn the NFT token
    function _burn(uint256 tokenCount) internal override(ERC721, ERC721URIStorage) {
        super._burn(tokenCount);
    }
    //return the TokenURI of the NFT token
    function tokenURI(uint256 tokenCount) public view override(ERC721, ERC721URIStorage) returns (string memory)
    {
        return super.tokenURI(tokenCount);
    }
}


ERC-20 Token vs ERC-721 Token

Below are some of the differences between the ERC-20 token and the ERC-721 token.

 

ERC-20

ERC-721

Fungibility First and foremost, these tokens are fungible in nature. There’s nothing like a tokenId. These tokens are non-fungible in nature. Each NFT has a uint256 variable known as tokenId.
Substitution     They’re easier for substitution. There is no scope for substitution.
Examples Tether (USDT), Dai (DAI), Bitcoin, Dogecoin, Wrapped Bitcoin (WBTC)  NFTs, in-game assets like money or in-game avatars, and even tickets. One of the most popular examples of these tokens is CryptoKitties. The purpose of the game is for users to breed, buy and sell virtual cats. In this game, the user fully owns an asset; a virtual cat that is unique and cannot be shared with anyone else.
Divisibility They’re divisible; ERC20 tokens can be divided in a number of ways. Even sharing 0.1 % of the token is possible.  They’re not divisible at all.
Fluctuation
  1. The value doesn’t fluctuate, since they’re not unique. 
  2. Requires one common smart contract.
  1. The value fluctuates according to rarity and uniqueness. 
  2. Requires unique smart contracts for each token.
Ownership No special ownership functions can be allocated. Special ownership functions can be enabled by these tokens.
Adoption These tokens are commonly adopted. These tokens have limited levels of acceptance.
Collectability These tokens are not collectible, they’re  interchangeable and represent a single entity These tokens can be collected like fiat currencies, they’re not interchangeable and represent a collection of assets
Token identity There is no KYC verification required. The KYC verification is in-built.
Values In ERC20 standards, there’s no difference in values. The values of each token are different.
 Challenges faced ERC20 token faces the challenge of them being lost when are being transferred to other wallets or smart contracts that don’t support ERC20 tokens.  ERC721’s token standards’ main challenge is that transferring numerous assets can become very expensive.


Similar Reads

Use of Ethereum's RLPx in Ethereum Ecosystem
Ethereum's RLPx is a set of protocols called RLPx. By employing a modified version of the Kademlia node discovery protocol, it maintains the P2P overlay network (using UDP messages). The protocol could be known as RLPx node discovery. When two peers first encounter one another, they ought to shake hands in two phases (i.e. two different handshakes)
3 min read
Ethereum (ETH) vs Ethereum Classic (ETC) in Blockchain
Ethereum is an open-source, decentralized blockchain platform with smart contract functionality. Ether (ETH) is a native cryptocurrency of the Ethereum blockchain platform. Ether is used to pay transaction fees and computational services. Developers can write smart contracts that receive, hold, and send Ether. It is a transactional token that facil
2 min read
How to Send ERC20 Token with Web3.js?
Sending ERC20 tokens is a common task in the world of Ethereum and decentralized applications. ERC20 tokens are a type of digital asset that lives on the Ethereum blockchain and follows a specific set of rules. The article focuses on discussing how to send ERC20 tokens using Web3.js, a popular JavaScript library for interacting with the Ethereum bl
7 min read
What is ERC721 Token?
ERC or Ethereum Request for Comments is simply a guideline or a template that all Ethereum-based tokens should follow. Ethereum’s smart contract programmers are accountable for writing ERC-related documents to describe the set of rules that every Ethereum-based Token must follow. A token is basically a digital asset that represents something. It ca
7 min read
Ethereum 2.0
Ethereum 2.0 is the next major upgrade for the Ethereum blockchain, which is currently the largest decentralized platform in the world. This upgrade brought several new features and improvements to the Ethereum network, making it more scalable, efficient, and secure. One of the most important aspects of Ethereum 2.0 is its switch from a Proof-of-Wo
9 min read
Difference Between Bitcoin and Ethereum
Bitcoin is a digital currency that can be transferred on a peer-to-peer (P2P) network without the need for any central authority. It was invented by a person or group of people with the name Satoshi Nakamoto in 2008. All the transactions are stored in an immutable distributed ledger. Bitcoin is created, stored, transacted, and distributed using a d
4 min read
Application Binary Interface(ABI) in Ethereum Virtual Machine
Smart contracts are pieces of code that are stored on the blockchain and are executed by the Ethereum Virtual Machine (EVM). The EVM also provides a comprehensive instruction set called opcodes which execute certain instructions. Opcodes are low-level codes similar to the processor's instruction set. The common Ethereum opcodes can be accessed from
5 min read
Interacting With Ethereum Smart Contract Using Web3js
Ethereum is a cryptocurrency platform in the market just like Bitcoin. It is an open-source &amp; decentralized blockchain featuring working on smart contracts. It has its own cryptocurrency known as ether. The smart contracts in Ethereum are written in solidity. TestRPC The Ethereum TestRPC is like a manual emulator for blockchain. It provides blo
4 min read
What is Ethereum Mempool?
In blockchain terminologies, we often come across a term called a mempool. A mempool or a memory pool is basically a waiting area for pending transactions. This article focuses on discussing mempool in Ethereum. The following topics will be discussed here: What is Ethereum Mempool?What is the Use of Ethereum Mempool?How Does the Mempool Work? How D
7 min read
What are Nodes and Clients in Ethereum?
Ethereum is the distributed blockchain network of computers running software that can verify blocks and transactions. The software is known as a client that must be running into an Ethereum Node. The following article discusses the following topics of Ethereum Node and Ethereum Client: What is Ethereum Node?Types of Ethereum NodeWhat is Ethereum Cl
7 min read
three90RightbarBannerImg