This short tutorial will explain what mintable ERC20 tokens are, what is the difference between minting and mining, what is Minter role and how to add, remove and transfer it. You'll find out what are some successful mintable ERC20 token projects, and how mintable tokens are used in crowdsales.
Mintable tokens can be created using our ERC20 token generator tool. If you want to learn about Ethereum tokens, we recommend you create one, and try it out. It's free when you are using Ropsten testnet. Take a look at create tokens page to learn how to create one.
In this tutorial, we are going to talk about OpenZeppelin's implementation of Mintable token which is battle-tested framework and used by our token generator.
Mintable tokens are ERC20-compatible tokens with one added feature: new tokens can be created at any time and added to total supply. Standard ERC20 tokens don't have this feature, which makes them a fixed supply tokens.
Mint function is defined like this in Solidity:
function mint(address to, uint256 value) public onlyMinter returns (bool)
New tokens can be minted only by an address which is set to be in a Minter role. If no address is in Minter role, then
no one can create new tokens.
Minter role is an address that has a special privilege to create new tokens, thus adding them to total supply. There could be multiple Minter role addresses, but in practice, it's usually just one address. The first Minter is the address that deployed the token contract. Current minter can add new minter, renonunce his privilege to be minter, or transfer his right to other address.
When a Minter wants to add another Minter, he can call the following function:
function addMinter(address account) public onlyMinter
We can see that by using function modifier onlyMinter only current Minter can add a new Minter. Calling addMinter
function emits the following event:
event MinterAdded(address indexed account)
Current Minter can renounce his privilege by calling the following function:
function renounceMinter() public
Only address that is Minter can renounce itself from Minter role, no one else. Calling renounceMinter
function emits the following event:
event MinterRemoved(address indexed account)
Current Minter can transfer his privilege by calling the following function:
function transferMinterRole(address newMinter) public
Function transferMinterRole adds new minter and renounces Minter role privilege in one transaction. It emits
both MinterAdded and MinterRemoved events.
Minting is not the same as mining. This is a common misunderstanding when people are talking about cryptocurrencies.
Minting tokens is done by sending a transaction that creates new tokens inside of token smart contract. As we have seen in What are mintable tokens, a call to a smart contract function can create unlimited number of tokens, without spending energy.
On the other hand, mining does create new tokens, but is usually limited as per concensus rules of that blockchain, and requires spending energy. Mining also serves other purposes like securing the network and packing new transactions into blocks.
There are plenty of mintable ERC20 tokens out there. Here are some of the more interesting tokens.
DAI is decentralized stablecoin pegged to $1 USD used in the MakerDAO system. Users can lock their crypto assets (ETH) inside of MakerDAO contract, and in return get DAI tokens. Everytime ETH is locked in CDP (Collateralized Debt Position), new DAI tokens are minted by the MakerDAO contract.
Status is an open-source platform which uses it's native SNT token as a mechanism for governance of the Status client, as a utility token to drive push notifications in their messaging app, as well as for curation of user-generated content on their network. The SNT token has a cap on total supply, but a lower current circulating supply. New tokens can be minted by the controler address.
Decentraland is a virtual world platform owned by its users. Users create goods and services and trade them using MANA tokens. MANA tokens are mintable and burnable ERC20 tokens.
Mintable tokens are widely used in combination with crowdsales. Crowdsale contracts are used to create an ICO where ERC20 tokens are sold for ETH. Here's the mechanism used for combining mintable tokens with crowdsale:
If you've completed this tutorial, we recommend you follow up with these tutorials: