Open In App

ERC20 vs ERC721 in Ethereum

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.



 

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. 

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:

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.

Example of ERC-20 Token :- 




// 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.

Components in ERC-721 token:

The ERC721 has the following important functions:

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:




// 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.

Article Tags :