ERC20 vs ERC721 in Ethereum - GeeksforGeeks

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 15

4/5/24, 1:05 AM ERC20 vs ERC721 in Ethereum - GeeksforGeeks

Trending Now DSA Web Tech Foundational Courses Data Science Practice Problem Python

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.

https://www.geeksforgeeks.org/erc20-vs-erc721-in-ethereum/ 1/15
4/5/24, 1:05 AM ERC20 vs ERC721 in Ethereum - GeeksforGeeks

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.

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.

https://www.geeksforgeeks.org/erc20-vs-erc721-in-ethereum/ 2/15
4/5/24, 1:05 AM ERC20 vs ERC721 in Ethereum - GeeksforGeeks

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

https://www.geeksforgeeks.org/erc20-vs-erc721-in-ethereum/ 3/15
4/5/24, 1:05 AM ERC20 vs ERC721 in Ethereum - GeeksforGeeks

“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

https://www.geeksforgeeks.org/erc20-vs-erc721-in-ethereum/ 4/15
4/5/24, 1:05 AM ERC20 vs ERC721 in Ethereum - GeeksforGeeks

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 Toke

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
https://www.geeksforgeeks.org/erc20-vs-erc721-in-ethereum/ 5/15
4/5/24, 1:05 AM ERC20 vs ERC721 in Ethereum - GeeksforGeeks

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()
https://www.geeksforgeeks.org/erc20-vs-erc721-in-ethereum/ 6/15
4/5/24, 1:05 AM ERC20 vs ERC721 in Ethereum - GeeksforGeeks

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.
/// @title A contract for demonstrate ERC-721 Token
/// @author Jitendra Kumar
/// @notice For now, this contract just show how to create an ERC-721 Tok
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, ERC721UR
super._burn(tokenCount);
}
https://www.geeksforgeeks.org/erc20-vs-erc721-in-ethereum/ 7/15
4/5/24, 1:05 AM ERC20 vs ERC721 in Ethereum - GeeksforGeeks

//return the TokenURI of the NFT token


function tokenURI(uint256 tokenCount) public view override(ERC721, ER
{
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

First and foremost,


These tokens are non-
these tokens are
fungible in nature. Each NFT
Fungibility fungible in nature.
has a uint256 variable known
There’s nothing like a
as tokenId.
tokenId.

Substitution They’re easier for There is no scope for


substitution. substitution.

NFTs, in-game assets like


money or in-game avatars,
and even tickets. One of the
most popular examples of
Tether (USDT), Dai these tokens is CryptoKitties.
(DAI), Bitcoin, The purpose of the game is
Examples
Dogecoin, Wrapped for users to breed, buy and
Bitcoin (WBTC) 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.

https://www.geeksforgeeks.org/erc20-vs-erc721-in-ethereum/ 8/15
4/5/24, 1:05 AM ERC20 vs ERC721 in Ethereum - GeeksforGeeks

ERC-20 ERC-721

They’re divisible;
ERC20 tokens can be
divided in a number of
Divisibility They’re not divisible at all.
ways. Even sharing 0.1
% of the token is
possible.

1. The value doesn’t


1. The value fluctuates
fluctuate, since
according to rarity and
they’re not unique.
uniqueness.
Fluctuation 2. Requires one
2. Requires unique smart
common smart
contracts for each token.
contract.

No special ownership Special ownership functions


Ownership functions can be can be enabled by these
allocated. tokens.

These tokens are These tokens have limited


Adoption
commonly adopted. levels of acceptance.

These tokens are not These tokens can be collected


collectible, they’re like fiat currencies, they’re not
Collectability interchangeable and interchangeable and
represent a single represent a collection of
entity assets

Token There is no KYC The KYC verification is in-


identity verification required. built.

In ERC20 standards,
The values of each token are
Values there’s no difference in
different.
values.

https://www.geeksforgeeks.org/erc20-vs-erc721-in-ethereum/ 9/15
4/5/24, 1:05 AM ERC20 vs ERC721 in Ethereum - GeeksforGeeks

ERC-20 ERC-721

ERC20 token faces the


challenge of them
being lost when are ERC721’s token standards’
Challenges being transferred to main challenge is that
faced other wallets or smart transferring numerous assets
contracts that don’t can become very expensive.
support ERC20
tokens.

Get 90% Course fee refund in just 90 Days! Also get 1:1 Mock
Interview, Job assistance and more additional benefits on selected
courses. Take up the Three 90 challenge today!

Here's a complete roadmap for you to become a developer: Learn DSA


-> Master Frontend/Backend/Full Stack -> Build Projects -> Keep
Applying to Jobs

And why go anywhere else when our DSA to Development: Coding


Guide helps you do this in a single program! Apply now to our DSA to
Development Program and our counsellors will connect with you for
further guidance & support.

Last Updated : 27 Feb, 2023 2

Previous Next

Centralized vs Decentralized What is Chaincode in Hyperledger


Applications Fabric?

https://www.geeksforgeeks.org/erc20-vs-erc721-in-ethereum/ 10/15
4/5/24, 1:05 AM ERC20 vs ERC721 in Ethereum - GeeksforGeeks

Share your thoughts in the comments Add Your Comment

Similar Reads
Use of Ethereum's RLPx in Ethereum (ETH) vs Ethereum
Ethereum Ecosystem Classic (ETC) in Blockchain

How to Send ERC20 Token with What is ERC721 Token?


Web3.js?

Ethereum 2.0 What is Ethereum?

Difference Between Bitcoin and Application Binary Interface(ABI) in


Ethereum Ethereum Virtual Machine

Interacting With Ethereum Smart What is Ethereum Mempool?


Contract Using Web3js

Z zehraina

Article Tags : Ethereum , Blockchain , Difference Between

https://www.geeksforgeeks.org/erc20-vs-erc721-in-ethereum/ 11/15
4/5/24, 1:05 AM ERC20 vs ERC721 in Ethereum - GeeksforGeeks

A-143, 9th Floor, Sovereign Corporate


Tower, Sector-136, Noida, Uttar Pradesh -
201305

Company Explore
About Us Job-A-Thon Hiring Challenge
Legal Hack-A-Thon
Careers GfG Weekly Contest
In Media Offline Classes (Delhi/NCR)
Contact Us DSA in JAVA/C++
Advertise with us Master System Design
GFG Corporate Solution Master CP
Placement Training Program GeeksforGeeks Videos
Geeks Community

Languages DSA
Python Data Structures
Java Algorithms
C++ DSA for Beginners
PHP Basic DSA Problems

https://www.geeksforgeeks.org/erc20-vs-erc721-in-ethereum/ 12/15
4/5/24, 1:05 AM ERC20 vs ERC721 in Ethereum - GeeksforGeeks

GoLang DSA Roadmap


SQL DSA Interview Questions
R Language Competitive Programming
Android Tutorial

Data Science & ML Web Technologies


Data Science With Python HTML
Data Science For Beginner CSS
Machine Learning Tutorial JavaScript
ML Maths TypeScript
Data Visualisation Tutorial ReactJS
Pandas Tutorial NextJS
NumPy Tutorial NodeJs
NLP Tutorial Bootstrap
Deep Learning Tutorial Tailwind CSS

Python Tutorial Computer Science


Python Programming Examples GATE CS Notes
Django Tutorial Operating Systems
Python Projects Computer Network
Python Tkinter Database Management System
Web Scraping Software Engineering
OpenCV Tutorial Digital Logic Design
Python Interview Question Engineering Maths

DevOps System Design


Git High Level Design
AWS Low Level Design
Docker UML Diagrams
Kubernetes Interview Guide
Azure Design Patterns
GCP OOAD
DevOps Roadmap System Design Bootcamp
Interview Questions

https://www.geeksforgeeks.org/erc20-vs-erc721-in-ethereum/ 13/15
4/5/24, 1:05 AM ERC20 vs ERC721 in Ethereum - GeeksforGeeks

School Subjects Commerce


Mathematics Accountancy
Physics Business Studies
Chemistry Economics
Biology Management
Social Science HR Management
English Grammar Finance
Income Tax

UPSC Study Material Preparation Corner


Polity Notes Company-Wise Recruitment Process
Geography Notes Resume Templates
History Notes Aptitude Preparation
Science and Technology Notes Puzzles
Economy Notes Company-Wise Preparation
Ethics Notes Companies
Previous Year Papers Colleges

Competitive Exams More Tutorials


JEE Advanced Software Development
UGC NET Software Testing
SSC CGL Product Management
SBI PO Project Management
SBI Clerk Linux
IBPS PO Excel
IBPS Clerk All Cheat Sheets

Free Online Tools Write & Earn


Typing Test Write an Article
Image Editor Improve an Article
Code Formatters Pick Topics to Write
Code Converters Share your Experiences
Currency Converter Internships
Random Number Generator

https://www.geeksforgeeks.org/erc20-vs-erc721-in-ethereum/ 14/15
4/5/24, 1:05 AM ERC20 vs ERC721 in Ethereum - GeeksforGeeks

Random Password Generator

@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved

https://www.geeksforgeeks.org/erc20-vs-erc721-in-ethereum/ 15/15

You might also like