If you are a developer building an Ethereum Dapp or an ICO, you probably heard of Ethereum token standards. ERC20, ERC721 etc… New token standards are created every week, and it’s difficult to keep up and know which tokens are important and useful for your Dapp. In this article, I will introduce the 2 most important token standards, i.e ERC20 and ERC721. For each of them, I will explain you:
- What are they used for?
- How they work?
- Implementations
- Wallet support
1. ERC20
ERC20 is the most popular Ethereum token standard. It became famous in 2017 thanks to its wide-spread use by ICO projects.
What are they used for?
ERC20 tokens can represent:
- Ownership in the company (share) or organization
- Rights to receive future interests/dividends
- Voting rights in an organization
- Voucher to be redeemed against a service or money
It is worth noting that ERC20 tokens are fungible, which means if I own 1 unit of token X, I can exchange it against any other unit of token X.
ERC20 tokens can be used in:
- ICOs: In these projects investors typically send ether to a smart contract and get ERC20 tokens back in return.
- Investment vehicles: ERC20 tokens can be used in investment funds and grant their holder interests
- Staking: Similar to the previous can send real ether t ERC20 tokens
- Game virtual assets: it could be an internal currency used to upgrade a character for example
How it works?
Each ERC20 token is managed by a single smart contract. This smart contract acts as the central bank for this token. It can: Transfer tokens from one owner to another Allow one Ethereum address to control the tokens of another address (delegated transfers) Give you the token balance of any Ethereum address
Tokens can be controlled by Externally Owned Account (EOA, most likely controlled by a human) or by a smart contract.
There are 3 main functions:
transfer()
transferFrom()
approve()
The most simple way to transfer tokens is to call the transfer()
function. Only the owner of the token can call this function:
function transfer(address to, uint tokens)
The other way of transferring tokens is by calling transferFrom()
. Any address that has been authorized by the owner of the tokens can call this function and transfer tokens on their behalf. This is a 2 way
First the owner of the tokens has to approve another address (the spender
argument) to spend a certain amount of tokens (tokens
argument):
approve(address spender, uint tokens)
Once this is done, the spender
can transfer tokens on behalf of the user, from the user address (from
argument) to any other address (to
argument). However the spender
can only spend up to the amount of tokens specified during the previous step (tokens
argument):
transferFrom(address from, address to, uint tokens)
You can read more in details on the ERC20 specification.
Where can we find good implementations for ERC20 token standard?
Implementations
There are 2 leading implementations for the ERC20 standard:
I recommend to use the one of OpenZeppelin because it is the most up-to-date.
Wallet Support
End-users will need to use their wallets to interact with your Dapp and your token. Fortunately, a lot of Ethereum wallets support ERC20 tokens, including the wildly popular Metamask wallet:
- Metamask
- Trust Wallet
- Coinbase wallet (formerly Toshi)
Useful links
- Official specification
- Implementation – From OpenZeppelin
2. ERC721
The ERC721 standard is the second most popular token standard after ERC20. While ERC20 tokens are all identical and fungible (i.e any token can be swapped with another one), ERC721 are all unique and non-fungible.
What are they used for?
This property makes it ideal to represent any kind of unique asset:
- Game virtual assets
- Art trade
- Real estate
So far the vast majority of ERC721 tokens were created for game virtual assets. You might have heard of Cryptokitties, the Ethereum game where you can collect virtual kitties. It became wildly popular when it was launched in late 2017 and it was one of the first Dapp to use ERC721 tokens. In Cryptokitties, each virtual kitty is represented by an ERC721 token.
How it work?
There are 3 main functions:
transferFrom()
safeTransferFrom()
approve()
The contract manages a set of unique tokens identified by their tokenId
. Each token has a single owner.
If the owner of a unique token identified as _tokenId
wants to transfer the token from his address to an address _to
, he will need to call the transferFrom
function (no need to supply the from
argument when the token owner is the sender) :
transferFrom(address _from, address _to, uint256 _tokenId)
Like ERC20, ERC721 also provides a way to do delegated transfers. However, contrary to ERC20 tokens, for ERC721 the same function (transferFrom()
) is used both for simple transfers and delegated transfers. When using transferFrom()
for a delegated transfer the _from
address has to be specified.
When you transfer a token to another address, if that address is a smart contract and was not designed to deal with this kind of token, the token will be stuck for ever in the smart contract. Inspired by ERC223, ERC721 has a function that perform a check to see this situation does not happen:
onERC721Received(address _operator, address _from, uint256 _tokenId, bytes _data)
Like for ERC20, the ERC721 specification is just a standard, and does not define implementations. Where can we find standard implementations for the ERC721 standard?
Implementation
There are 2 leading implementations for the ERC721 standard:
Again, I recommend to use the one of OpenZeppelin. because it is the most up-to-date.
Alright, but which wallet support the ERC721 standard?
Wallet Support
Contrary to ERC20 tokens, the wallet support for ERC721 tokens is not as good, even though it’s improving. Notably, Metamask does not support ERC721 yet. These wallets support ERC721 tokens:
- Trust Wallet
- Coinbase wallet (formerly Toshi)
Useful links
- Official specification
- erc721.org – Community page to explain the standard
- Implementation – From OpenZeppelin
ERC20 vs ERC721
Token | Unique tokens | Fungible | Popularity | Wallet Support |
---|---|---|---|---|
ERC20 | No | Yes | High | Good |
ERC721 | Yes | No | Medium | Medium |
Leave a Reply