[Ethereum] Mintable Token with Inflation

soliditytokens

I am looking for example of implementation of mintable token where minting happens automatically based on certain rules (e.g. percentage of inflation per year that reduces overtime).

OpenZeppelin has MintableToken implementation https://github.com/OpenZeppelin/zeppelin-solidity/blob/master/contracts/token/MintableToken.sol

That implementation assumes that owner calls mint function wherever required.

What is the best way to make minting happen automatically?

I was thinking to add mint logic call to 'transfer' function that would check if it is time to create new tokens and create them. Is it good approach?

Best Answer

When asking how to introduce inflation, you need to specify who receives the newly-minted tokens. Tokens don't magically lose value: you need to dilute the supply in a way that introduces more tokens into circulation. Would you like to mint new tokens into your own account and distribute them how you see fit using the transfer function? You can do that.

The approach I would recommend is to define how many tokens get created per block, and then you can either build it into the transfer function as you suggested (not recommended; see below) or add a separate function such as "claimTokens" that only you can call to have the amount of tokens calculated as:

tokens_per_block * (current_block_number - last_claim_block_number)

and set last_claim_block_number every time you make the claim.

I wouldn't recommend putting it into the transfer function because it'll make your transfers more expensive and also have to issue an extra Transfer event for every transfer, making it 2 instead of 1.

Related Topic