1

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?

4 Answers 4

3

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.

1
  • Thank you for the answer. As I continued research the question I came to the same conclusion. Commented Dec 17, 2017 at 5:24
1

I've seem some contracts implement a mint function that anybody can call. The contract has some limitation ie mint cannot be called more than once every minute. The account calling mint will be assigned the new created tokens.

1
  • Hi, could you point to some contracts that are implementing this? Commented Nov 28, 2017 at 20:25
0

As far as I know, the only way to do something automatically, is to call contract functions from some backend. For example, Node.js application periodically retrieves inflation percentage from somewhere and then calls a contract function for updating stored data. This function calls minting function with updated inflation data.

Adding minting logic to transfer function seems OK to me, but I would like to see the answer from more experienced developer.

0

You could use chainlink keepers instead of a back end process for auto-minting

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.