OpenZeppelin Part 3: Token Standards

Token Standards

OpenZeppelin has incorporated a series of token contracts to assist with creating and managing them.

What is a Token?

In Ethereum, tokens are a digital asset that can represent anything. It can be a protocol, physical object, or even cryptocurrency. People use them for a variety of actions such as buying or even voting. A token is a smart contract and a smart contract is a piece of code. To send a token you need to write a contract. Keep in mind that this contract must conform to a set of special standards to be able to interact with other tokens and smart contracts.

Types of Standards

In this tutorial, we cover the two types of standards that OpenZeppelin has made contracts for. Keep in mind that there are more standards.

ERC20

This standard is the most common for Ethereum tokens to follow. It describes the way tokens are transferred between addresses and how their data is accessed. Every ERC20 token is identical and equal to each other.

ERC721

This standard is for a non-fungible token. Non-fungible means that people cannot interchange these tokens whereas ERC20 tokens can be. ERC721 tokens are all unique and have special standards in relation to how they are managed, owned, and traded.

OpenZeppelin & ERC20

OpenZeppelin provides different contracts to assist with creating and interacting with an ERC20 token.

IER20: Defines the implementation all tokens should conform to.

ERC20: Basic implementation of the token.

ERC20Detailed: Allows you to add more information to your tokens such as name, symbol, and decimals.

ERC20Mintable: Allows anyone with the minter role to mint tokens aka create tokens.

ERC20Burnable: Allows you to destroy the token.

ERC20Capped: Maximum cap on tokens allowed.

ERC20Pausable: Allows anyone with the pauser role to freeze the transfer of tokens to and from users.

safeERC20: Forces transfers and approvals to succeed or the transaction reverts.

TokenTimelock: To release tokens after a specified timeout. Useful in an Escrow situation.

Usage

To use any of the features from the token library, import them at the top of your contract. import "openzeppelin-solidity/contracts/token/chosen standard". This allows you to inherit its functions into your contract.

Note: You can have multiple inheritances but they must all be for the same standard of token.