I would like to create a lottery. For that I would need to have a repeating payout event every 1h or 24h -> is this even possible with Solidity/Ethereum?


2 Answers 2


Solidity doesn't have a timer function. As time or date functions could potentially lead to non-deterministic behavior, which is a bad thing.

To achieve similar functionality, you could use the block timestamp or current block number to approximate a given time interval knowing the blocks are produced roughly every 14 seconds.

  • Hmm - does that mean, that it is not possible that a contract execute itself based on an event -> e.g. a timer or sth? Commented Jul 2, 2017 at 14:58
  • Also - have you seen this: ethereum-alarm-clock.com Commented Jul 2, 2017 at 15:38

To invoke any behavior that modifies state of an Ethereum contract it is necessary to send a transaction from an external address. So it is not possible to trigger any method call without having an external agent (so called "oracle") that would invoke a contract method.

What is possible though is to make the payout amount calculation dependent on time. So instead of doing the actual payout every 24 hours you would only do the payout when the recipient explicitly asks for it. At that time you would calculate how much should be sent to the recipient based on the time that passed from the moment you would start the cron job doing the payout.

  • You can do scheduling theoretically with oraclize - but what happens if the contract runs out of eth and the callback is never triggered again - then it is just broken right? Commented Jul 2, 2017 at 17:57
  • You can do up to 60 day scheduled queries into the future, and in case of the contract running out of funds to pay this, there can always be an escape hatch to manually call it.
    – DenisM
    Commented Jul 7, 2017 at 9:36

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