Changing the Supply of ERC20 Tokens

[EDIT 2018-05-25] This post has been edited to introduce a BaseERC20Token contract.

This short post will add dynamic control of the total supply of tokens to the previously introduced
simple ERC20 tokens.

Our previous ERC20 tokens made the simplifying assumption that the token’s total supply did not change. I’m going to relax that assumption in this post by allowing the owner to increase the token supply with a “mint” function. Similarly, “burn” and “burnFrom” functions can decrease the total supply.

Future posts will make use of the ability to dynamically create and destroy tokens.

Setting the Initial Token Supply

The new MintableToken contract will inherit from a BaseERC20Token contract and augment that with functions to mint and burn tokens. BaseERC20Token is a fully parameterized version of the SimpleERC20Token contract. The full source code can be found at the end of this post.

pragma solidity^0.4.23;import"baseerc20token.sol";contractMintableTokenisBaseERC20Token{addresspublicowner=msg.sender;constructor(uint256_totalSupply,uint8_decimals,string_name,string_symbol)BaseERC20Token(_totalSupply,_decimals,_name,_symbol)public{}// more to come}

Minting Tokens

The contract’s owner can create new tokens by calling mint. This increases the total token supply and grants ownership of the new tokens to the specified recipient: