Is there maybe a way to program a contract to mint a certain amount of tokens over regular periods of time automatically? Say, I would like a contract to create 1 000 new tokens once a year on Dec., 31st for next 100 years Many thanks


Contract functions only run if some user or other contract initiates a call to that function. Therefore, it would not be possible to create a function which on its own runs regularly based on block number or date. You could create an external service which calls the addMoreTokens function regularly, but that does not sound like what you want.

It seems like you are trying to create a 'pot' of tokens which grows over time. I think you would be able to achieve this by minting all the tokens up front, and then limiting the number of tokens which can be 'withdrawn' using the current date.

Here is some pseudo-code:

function withdrawTokens (_amount) {
  //calculate fraction of tokens that should be available
  fraction = ((currentTime - startTime)/(finalTime - startTime))

  //calculate number of tokens available to give out
  tokensAvailable = (fraction * totalTokens) - tokensAlreadyGivenOut

  //check that the amount being requested is less than tokens available
  require(tokesAvailable > _amount)

  //increase number of tokens already given out
  tokensAlreadyGivenOut += _amount

  //grant the user the new tokens
  tokens[msg.sender] += _amount

I am not a super expert here, but sounds like this is a possible solution.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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