Token standards introduction: ERC-20, ERC-777, ERC-721, and ERC-1155
Introduction
With the rise in popularity of blockchain technologies and cryptocurrencies, we are seeing many more tokens being created. But what are they, exactly? This post will go over some of the most common types of crypto tokens: ERC-20, ERC-777, ERC-721, and ERC-1155.
What are tokens?
Tokens are digital assets built on a cryptocurrency’s blockchain. They differ from coins because while a coin is built on its native blockchain, a token is built on an existing blockchain.
For example, ETH is the official coin for the Ethereum blockchain, while Basic Attention Token (BAT), Chainlink (LINK), or OmiseGo (OMG) are tokens built on Ethereum.
Tokens are often a quicker way to leverage the existing standards of a successful and popular blockchain while building digital assets. Their most common use case is smart contracts on decentralized applications (DApps).
Difference between fungible and non-fungible tokens
Tokens generally fall under two categories: fungible tokens and non-fungible tokens.
Fungible tokens are divisible digital assets that you can swap for other assets of the same type. No single unit is worth more or less than another. Think about how a dollar bill is similar to another one and can be easily exchanged.
On the other hand, non-fungible tokens (also known as NFTs) are digital assets that you cannot easily exchange for other assets due to their uniqueness. For example, consider an artwork that holds a particular value for its owner and would be difficult to exchange for another artwork because their perceived values are different.
What are token standards? ERCs and EIPs
Before the adoption of token standards, blockchain developers often created tokens according to personal preferences, causing token ecosystems to experience difficulties when interacting with each other and limiting interoperability.
To solve this problem, Ethereum developers now create ERCs (Ethereum Request for Comments) and EIPs (Ethereum Improvement Proposals). These help to define the rules and required functions for tokens created on the Ethereum blockchain, making integrations and interactions much more accessible.
What are ERC-20 tokens?
ERC-20 is a protocol that defines standard APIs for creating fungible tokens in a smart contract. It was created in 2015 by Fabian Vogelsteller.
Its main methods include:
name()
(optional): The name of the token.symbol()
(optional): The symbol of the token.decimals()
(optional): The decimal places of the token. This allows for fungibility.totalSupply()
: The total number of existing tokens.balanceOf()
: The total number of tokens owned by a particularaccount
.transfer()
: Moves a number of tokens from the caller’s account to a specifiedaddress
.transferFrom()
: Same astransfer()
, but it also specifies the address to move tokens from.allowance()
: The number of tokens aspender
is allowed to spend on behalf of theowner
viatransferFrom()
.approve()
: Sets the number of tokens aspender
is allowed to spend.
All these methods are strictly required in an ERC-20 smart contract, apart from the first three marked (optional) which help to improve usability.
An ERC-20 also has two events—Transfer
(which triggers when tokens are transferred) and Approved
(which triggers on any successful call to the approve()
method).
Examples of ERC-20 tokens are USDC, a stablecoin pegged to the dollar, or UNI, the governance token used in Uniswap to vote on changes on the platform.
Many projects use ERC-20 tokens during their fundraising period (known as ICO – Initial Coin Offering). They are also widely used for trading purposes—some exchanges only support trading in tokens that adhere to this standard due to their popularity among investors and traders.
What are ERC-777 tokens?
The ERC-777 standard offers improvements in how users interact with fungible tokens in a smart contract while remaining backward compatible with ERC-20. It was created in 2017 by Jacques Dafflon, Jordi Baylina, and Thomas Shabibi.
Some of its improvements include clearing the confusion around decimals in a smart contract and introducing hooks that allow your smart contract to react when you send or receive tokens. These help to prevent tokens from getting locked forever or lost when sent to the wrong address.
ERC-777 contains methods like:
granularity()
: The smallest part of the token that is not divisible.send()
: Sends a specificamount
of tokens to arecipient
burn()
: Destroys a specificamount
of tokens, which reduces thetotalSupply
.isOperatorFor()
: Checks if an account is an operator.authorizeOperator()
: Makes an account an operator.revokeOperator()
: Revokes an account’s operator status.defaultOperators()
: Returns a list of token holders who are default operators.tokensToSend()
: This hook is called when tokens are about to be destroyed or movedfrom
a specific holder’s address. It is triggered before the smart contract’s state is updated and can prevent the operation from being executed.tokensReceived()
: This hook is called when tokens are about to be destroyed or movedto
a specific holder’s address. It is triggered after the smart contract’s state is updated, which can prevent the operation from being executed.
What are ERC-721 tokens?
ERC-721 is a standard for creating non-fungible tokens (NFTs) on Ethereum. It was created in 2018 by Dieter Shirley, Jacob Evans, Natassia Sachs, and William Entriken.
A few examples include rare collectibles (e.g., CryptoKitties and Gods Unchained), or limited edition items like sneakers and art prints.
They can also signify membership in a community, like Developer DAO.
A basic ERC-721 smart contract contains methods like:
balanceOf()
: The number of tokens in theowner
‘s account.ownerOf()
: ThetokenId
of the owner.safeTransferFrom()
: Safely transfers tokens from the owner’s address to the recipient’s. ThetokenId
must be specified as a parameter.transferFrom()
: Same function assafeTransferFrom()
, but generally not recommended.approve()
: Allows an address to transfer a token identified by itstokenId
, into another account. It triggers theApproval
event.setApprovalForAll()
: Allows anoperator
to callsafeTransferFrom
ortransferFrom
for any token owned by the caller.getApproved()
: Gets the approved account for a specifictokenId
.isApprovedForAll()
: Checks if anoperator
is allowed to manage all the assets of theowner
.
It also contains events like Transfer
(which triggers when ownership of any NFT changes) and Approval
(which activates when the approved address for an NFT is changed).
ERC-721 has multiple extensions split across different contracts.
Here are two such extensions.
What are ERC721Enumerable?
The ERC721Enumerable contains all the methods available in the original ERC721 and three extra methods:
totalSupply()
: The total amount of tokens in the contract.tokenOfOwnerByIndex()
: ThetokenId
of an owner’s address at a givenindex
in its token list. You can use it withbalanceOf
to enumerate all of theowner
‘s tokens.tokenByIndex()
: ThetokenId
at a givenindex
. You can use it withtotalSupply
to enumerate all tokens.
This extension is often not implemented because enumerating tokens on the blockchain could significantly spike gas costs.
What is ERC721A?
ERC721A is an extension of ERC-721 that aims to significantly reduce transaction fees by allowing users to mint multiple unique NFTs in a single transaction.
It was created by the Azuki team in 2022 and is currently used by projects like Dastardly Ducks and Zero Gravity Club.
In addition to the original ERC721 methods, it contains extra methods like:
_startTokenId()
: The starting token ID._nextTokenId()
: The next token ID to be minted._totalMinted()
: The total amount of minted tokens._numberMinted()
: The number of tokens minted by anowner
._getAux()
: Gets the auxiliary data for anowner
(e.g., the number of whitelist mint slots used.)_setAux()
: Sets the auxiliary data for anowner
_ownershipOf()
: The token ownership data for a specifictokenId
._initializeOwnershipAt()
: This can be used to initialize some tokens in a large batch to reduce first-time transfer costs. It initializes token ownership data at theindex
slot._mint()
: Mints a number of tokens and transfers them to a specific address._safeMint()
: Same functionality as_mint
, but it contains adata
parameter which gets forwarded to contract recipients inIERC721Receiver.onERC721Received
._beforeTokenTransfers()
: This hook is called before a token ID set is about to be transferred. It is also called before burning one token. It contains thestartTokenId
and thequantity
of tokens._afterTokenTransfers()
: This hook is called after a set of token IDs are to be transferred.
What are ERC-1155 tokens?
The ERC1155 protocol combines the abilities of ERC-20 and ERC-721, allowing tokens to have fungible and non-fungible characteristics. It was created by Witek Radomski and made public in 2019.
ERC-1155 provides a way to model assets and their ownership, as well as a way to create, transfer, and settle those assets. With these capabilities, you can trade fungible assets like gold bullion, or collectibles such as art, baseball cards, loyalty points, etc., using the same smart contract.
In an ERC-1155 smart contract, the balanceOf()
method contains an id
argument to identify the token you want to query its balance.
It also contains other methods like:
balanceOfBatch()
: It returns the balance in a batch of accounts with specified ids.setApprovalForAll()
: Allows anoperator
to transfer acaller
‘s tokens.isApprovedForAll()
: Checks if anoperator
is allowed to transfer acaller
‘s tokens.safeTransferFrom()
: Transfers a number of tokens from acaller
‘s address to a recipient’s address. The tokens must have a type ofid
.safeBatchTransferFrom()
: Same functionality assafeTransferFrom()
but in batches.
Conclusion
The first step in creating a smart contract is deciding the right tool for the job. You can choose to create a simple fungible token based on ERC-20, improve its features based on ERC-777, create NFTs with ERC-721, or hybrid smart contracts with ERC-1155.
Other token standards exist with their specific use-cases, like ERC-4626 for tokenized vaults and you can learn more about crypto tokens through our blog or these resources listed below.
Resources
- Discover how you can save thousands in infra costs every month with our unbeatable pricing on the most complete Web3 development platform.
- Input your workload and see how affordable Chainstack is compared to other RPC providers.
- Connect to Ethereum, Solana, BNB Smart Chain, Polygon, Arbitrum, Base, Optimism, Avalanche, TON, Ronin, zkSync Era, Starknet, Scroll, Aptos, Fantom, Cronos, Gnosis Chain, Klaytn, Moonbeam, Celo, Aurora, Oasis Sapphire, Polygon zkEVM, Bitcoin, Tezos and Harmony mainnet or testnets through an interface designed to help you get the job done.
- To learn more about Chainstack, visit our Developer Portal or join our Discord server and Telegram group.
- Are you in need of testnet tokens? Request some from our faucets. Multi-chain faucet, Sepolia faucet, Holesky faucet, BNB faucet, zkSync faucet, Scroll faucet.
Have you already explored what you can achieve with Chainstack? Get started for free today.