ERC Token Standards

Devin Bandara
Nirvana Labs

--

Written 23.12.2020

Introduction to Tokens

Image2 (source)

Tokens Overview

Tokens are pieces of software that represent some item of value on the blockchain. Common use cases include mediums of exchange, voting rights, scarce artistic works and collectibles, and real estate ownership. Smart Contracts interact with tokens, track tokens, exchange tokens, create tokens, and destroy tokens.

Tokens and Smart Contracts

ERC token standards guarantee that tokens of the same standard behave in the same way. Since token behavior is uniform among tokens of the same standard, Smart Contract interactions with tokens of the same standard are also uniform. Standard token behavior and Smart Contract interaction enable trustless applications.

Tokens and Token Contracts

Token contracts are Ethereum Smart Contracts that each describe and provide functionality for a specific token. Each token belongs to one token contract. One token contract might describe, track, and provide functionality for billions of tokens. The token contract tracks balances and performs the actual functions such as token minting and token transferring.

Token transfers require the sender to call the token contract’s transfer function for a given amount of token and the receiver. The token contract lowers the token balance of the sender by the amount sent and raises the token balance of the receiver by the same amount.

Token contracts provide an essential function as record keepers for Ethereum accounts and their token balances. An Ethereum account owns tokens if the Ethereum account’s token balance for a given token contract is greater than zero. Since balances are simply account-to-token-amount mappings in a secure database, tokens are an efficient method for representing monies, corporate rewards points, shares of an asset, or votes in a community.

Fungibility

Image3 (source)

Fungible

Fungible goods are equivalent and interchangeable. The US dollar is a fungible asset. Fungible token standards: ERC-20, ERC-223, and ERC-777.

Non-Fungible

Non-fungible assets are either unique or nearly unique, like deeds of ownership and collectibles. Non-Fungible tokens are called NFTs for short. Non-fungible token standards: ERC-721.

Hybrid-Fungibility

ERC-1155 is a fungibility-agnostic multi-token standard enabling a single token contract to represent arbitrary amounts of semi-fungible and non-fungible tokens. Additionally, the ERC-1155 standard batches operations, which increases gas efficiency.

Fungibility Comparison Chart (source)

Fungible Tokens

Image4 (source)

ERC-20

ERC-20 token contracts track ownership of fungible tokens. ERC-20 tokens of the same contract are equivalent and interchangeable.

ERC-20 tokens allow holders to transfer tokens and authorize Smart Contracts to transfer or perform other actions with tokens. The ERC-20 standard is minimal and does not encode much functionality outside of balance retrieval, transfers, minting, burning, and approving other accounts and Smart Contracts to use tokens on behalf of a specific owner. Individual ERC-20 tokens may possess special rights relative to other ERC-20 tokens of the same contract. This customization is not native to the ERC-20 token standard and is emblematic of the power of developing bespoke contracts that inherit one of the ERC token standard’s functionality.

There are numerous applications of the ERC-20 standard. USDC is a medium of exchange token pegged to the US dollar. YFI and MKR are governance tokens that grant holders the right to vote on the future of the respective decentralized finance protocol. Nodes on Chainlink’s decentralized oracle network receive the native LINK token in exchange for fetching external data for Smart Contracts.

ERC-223

ERC-223 is built on top of ERC-20 which incorporates all the functions of ERC-20 and also solves the problem of lost tokens due to accidental transfers. ERC-223 consumes less gas than ERC-20.

ERC-223 tokens can be accepted or rejected by a receiving account or Smart Contract. Rejecting tokens results in a failed transaction and the rejected tokens are returned to the sender.

Transferring ETH (Ethereum’s native currency) to Smart Contracts requires a different process and function than transferring tokens. Sending tokens to an account, such as an Ethereum wallet, only requires using the transfer method. On the other hand, transferring tokens to a Smart Contract requires approving the transfer and then using the transferFrom method. In the past, it was not uncommon for accounts to lose tokens by using the transfer method or forgetting to approve transfers to Smart Contracts before executing the transferFrom method. The confusion is also in part due to ETH not requiring approval to be transferred to contracts.

ERC-223 solves the problem of lost tokens by calculating the byte code length of the target address. Contract address lengths will be greater than zero and there is a function called tokenFallback which will be invoked. ERC-223 checks the bytecode length of the target address and searches for tokenFallback and hence does not transfer tokens if it is a contract address and solves the problem of lost tokens.

ERC-777

ERC-777 is an advanced token standard that attempts to solve the inefficiency of ERC-223 and ERC-20.

Operators: ERC-777 introduces “Operators” instead of an allowance mechanism. Operators are trustworthy Smart Contracts, which can move amounts on behalf of the user. Users authorize and revoke Operators.

Hooks: Hooks are functions on the token contract that are called when an account or contract sends or receives tokens. Hooks allow developers to code reactive contracts. Using the tokensToSend and tokensReceived hooks, it is now possible to add more fine-tuned control over token transfers and interactions. It enables the token recipient to automatically execute code when a token is received and it allows senders to execute code when a token is moved. If, for example, you accidentally send tokens to a Smart Contract address, they are not lost but can be automatically returned by the Smart Contract. This prevents the aforementioned inefficiency of the ERC-20, where two transactions (approve / transferFrom) are required to send tokens to a contract.

Backward compatibility: ERC-777 is backward compatible with ERC-20, meaning you can interact with these tokens as if they were ERC-20, using the standard functions, while still getting all of the advanced features of ERC-777. a token contract can implement both ERC-20 and ERC-777 in parallel. The read-only functions of both token standards also overlap without any problems.

Fungible Token Comparison Chart (source)

One of the setbacks in ERC-777 is that the gas cost is a little higher than ERC-20. An increase in gas costs also leads to an increase in the transaction costs of simple token transfers.

Non-Fungible Tokens

Image5 (source)

ERC-721

ERC-721 token contracts track ownership of unique tokens. It is typical to use the ERC-721 standard’s metadata URI specification to give the token human-readable data. The metadata URI can link to different URLs on the web. URLs typically link to artistic works or an image on the web that corresponds to the ERC-721 token’s value and identity.

ERC-721 contracts can mint more than one token where each token has a unique numeric identifier. This numeric identifier ensures uniqueness on the Ethereum network and is the reason why ERC-721 tokens have become the most common token standard for non-fungible tokens.

There are numerous applications of the ERC-721 standard. CryptoKitties are unique digital collectibles that partly originated the ERC-721 standard and NFT movement. Sorare is a trading card NFT for a fantasy soccer game. The ERC-721 soccer player card tokens trade on decentralized marketplaces. Rarible is a decentralized marketplace for selling ERC-721 tokens in the form of digital art and collectibles. The NBA’s Sacramento Kings use Ethereum to hold secure auctions for sports memorabilia. Winners receive a digital token of their memorabilia that tracks its ownership history. Game-used apparel is encoded with relevant and verified data for the exact game, season, and player. Decentraland is a virtual reality game where users buy and sell land. In the real world, real estate owners are also beginning to tokenize deeds and properties.

NFT ecosystem (source)

Hybrid-Fungibility Tokens

Image6 (source)

ERC-1155

ERC-1155 contracts attempt to take the best features from ERC-20 and ERC-721 contracts to create a fungibility-agnostic and gas-efficient token contract. New ERC-721 and ERC-20 tokens require entirely new contract deployments for new token generation. ERC-1155 contracts allow for minting arbitrary amounts of semi-fungible and non-fungible tokens. Since this token standard is newer, it is not fully adopted by all applications and protocols on Ethereum.

The gas-efficiency is realized by the ERC-1155 contract’s ability to execute batch operations. The contract even provides a generalized metadata URI for all tokens that the contract can then use to look-up an individual token’s specific metadata URI based on that token’s unique numeric identifier.

Since the ERC-1155 mints semi-fungible tokens as opposed to fungible tokens, it does not fully replicate the full functionality of the fungible token standards because the semi-fungible tokens minted via an ERC-1155 contract cannot be broken down into smaller pieces. This is a disadvantage if developers are using the ERC-1155 standard to code mediums of exchange because typically currencies are divisible.

Future

Image7 (source)

Tokenization and Smart Contracts enable developers to build value-based applications that were previously too difficult or impossible to build on the internet. The future of tokenization will continue to benefit the decentralized finance industry and hopefully begin to materially disrupt non-financial applications such as rewards systems, illiquid assets, and digital goods. Roughly four billion dollars of Bitcoin and tens of billions of US dollars are tokenized on Ethereum for usage in the myriad of decentralized finance applications. Companies and users are adopting tokenization at higher rates entering 2021. As tokenization matures, new use cases will emerge.

Reference

  1. “OpenZeppelin Contracts Documentation”: https://docs.openzeppelin.com/contracts/3.x/
  2. “The Non-Fungible Token Bible: Everything you need to know about NFTs”: https://opensea.io/blog/guides/non-fungible-tokens/
  3. “The Technology Behind Ethereum Tokens”: https://medium.com/mycrypto/the-technology-behind-ethereum-tokens-5615527e1af8
  4. EIP-20: ERC-20 Token Standard: https://eips.ethereum.org/EIPS/eip-20
  5. “ERC223-token-standard”: https://github.com/Dexaran/ERC223-token-standard
  6. “EIP-777: ERC777 Token Standard”: https://eips.ethereum.org/EIPS/eip-777
  7. “EIP-721: ERC-721 Non-Fungible Token Standard”: https://eips.ethereum.org/EIPS/eip-721
  8. “EIP-1155: ERC-1155 Multi Token Standard”: https://eips.ethereum.org/EIPS/eip-1155
  9. “Image1”: https://decrypt.co/resources/dapps
  10. “Image2”: https://decrypt.co/resources/erc721-what-is-it-guide-ehtereum-token
  11. “Image3”: https://decrypt.co/resources/merkle-trees-guide-explainer-blockchain
  12. “Fungibility Comparison Chart”: https://opensea.io/blog/guides/non-fungible-tokens/
  13. “Image4”: https://decrypt.co/resources/erc20
  14. “Fungible Token Comparison Chart”: https://101blockchains.com/erc20-vs-erc223-vs-erc777/
  15. “Image5” https://decrypt.co/resources/non-fungible-tokens-nfts-explained-guide-learn-blockchain
  16. “NFT Ecosystem”: https://www.theblockcrypto.com/genesis/78736/nft-ecosystem-map-research
  17. “Image6”: https://decrypt.co/resources/dual-token-sales-explained-guide-makerdao
  18. “Image7”: https://decrypt.co/resources/oracles

--

--

Devin Bandara
Nirvana Labs

CEO & Founder @ Nirvana Labs - Enlightening Blockchain Infrastructure