Professional Documents
Culture Documents
ERC20 vs ERC721 in Ethereum - GeeksforGeeks
ERC20 vs ERC721 in Ethereum - GeeksforGeeks
ERC20 vs ERC721 in Ethereum - GeeksforGeeks
Trending Now DSA Web Tech Foundational Courses Data Science Practice Problem Python
https://www.geeksforgeeks.org/erc20-vs-erc721-in-ethereum/ 1/15
4/5/24, 1:05 AM ERC20 vs ERC721 in Ethereum - GeeksforGeeks
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.
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.
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.
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
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.
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()
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
Below are some of the differences between the ERC-20 token and the
ERC-721 token.
ERC-20 ERC-721
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.
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
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!
Previous Next
https://www.geeksforgeeks.org/erc20-vs-erc721-in-ethereum/ 10/15
4/5/24, 1:05 AM ERC20 vs ERC721 in Ethereum - GeeksforGeeks
Similar Reads
Use of Ethereum's RLPx in Ethereum (ETH) vs Ethereum
Ethereum Ecosystem Classic (ETC) in Blockchain
Z zehraina
https://www.geeksforgeeks.org/erc20-vs-erc721-in-ethereum/ 11/15
4/5/24, 1:05 AM ERC20 vs ERC721 in Ethereum - GeeksforGeeks
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
https://www.geeksforgeeks.org/erc20-vs-erc721-in-ethereum/ 13/15
4/5/24, 1:05 AM ERC20 vs ERC721 in Ethereum - GeeksforGeeks
https://www.geeksforgeeks.org/erc20-vs-erc721-in-ethereum/ 14/15
4/5/24, 1:05 AM ERC20 vs ERC721 in Ethereum - GeeksforGeeks
https://www.geeksforgeeks.org/erc20-vs-erc721-in-ethereum/ 15/15