Token standards introduction: ERC-20, ERC-777, ERC-721, and ERC-1155
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.
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.
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 particular
transfer(): Moves a number of tokens from the caller’s account to a specified
transferFrom(): Same as
transfer(), but it also specifies the address to move tokens from.
allowance(): The number of tokens a
spenderis allowed to spend on behalf of the
approve(): Sets the number of tokens a
spenderis 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
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.
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 specific
amountof tokens to a
burn(): Destroys a specific
amountof tokens, which reduces the
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 moved
froma 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 moved
toa specific holder’s address. It is triggered after the smart contract’s state is updated, which can prevent the operation from being executed.
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 the
tokenIdof the owner.
safeTransferFrom(): Safely transfers tokens from the owner’s address to the recipient’s. The
tokenIdmust be specified as a parameter.
transferFrom(): Same function as
safeTransferFrom(), but generally not recommended.
approve(): Allows an address to transfer a token identified by its
tokenId, into another account. It triggers the
setApprovalForAll(): Allows an
transferFromfor any token owned by the caller.
getApproved(): Gets the approved account for a specific
isApprovedForAll(): Checks if an
operatoris allowed to manage all the assets of the
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.
The ERC721Enumerable contains all the methods available in the original ERC721 and three extra methods:
totalSupply(): The total amount of tokens in the contract.
tokenIdof an owner’s address at a given
indexin its token list. You can use it with
balanceOfto enumerate all of the
tokenIdat a given
index. You can use it with
totalSupplyto enumerate all tokens.
This extension is often not implemented because enumerating tokens on the blockchain could significantly spike gas costs.
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.
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 an
_getAux(): Gets the auxiliary data for an
owner(e.g., the number of whitelist mint slots used.)
_setAux(): Sets the auxiliary data for an
_ownershipOf(): The token ownership data for a specific
_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 the
_mint(): Mints a number of tokens and transfers them to a specific address.
_safeMint(): Same functionality as
_mint, but it contains a
dataparameter which gets forwarded to contract recipients in
_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 the
_afterTokenTransfers(): This hook is called after a set of token IDs are to be transferred.
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 an
operatorto transfer a
isApprovedForAll(): Checks if an
operatoris allowed to transfer a
safeTransferFrom(): Transfers a number of tokens from a
caller‘s address to a recipient’s address. The tokens must have a type of
safeBatchTransferFrom(): Same functionality as
safeTransferFrom()but in batches.
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.
- Connect to the Ethereum, Polygon, BNB Smart Chain, Avalanche, Arbitrum, NEAR, Aurora, Fantom, Solana, Gnosis Chain, Harmony, Tezos and StarkNet mainnet or testnets through the interface designed to help you get the job done.
- Get access to the Ethereum, Polygon, BNB Smart Chain, Avalanche, Fantom, and Tezos archive nodes to query the entire history of the mainnet—starting at just $49 per month.
- Choose where you want to deploy, and we will provide you with the dedicated managed infrastructure that can handle high-volume, high-velocity read/write access to the network.
- To learn more about Chainstack, visit our Knowledge Center or join our Discord server and Telegram group.
Have you already explored what you can achieve with Chainstack? Get started for free today.