2

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?

marked as duplicate by niksmac, Richard Horrocks, Tjaden Hess, Rob Hitchens, Ismael Jul 2 '17 at 23:22

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

4

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? – Fabian Lurz Jul 2 '17 at 14:58
  • Also - have you seen this: ethereum-alarm-clock.com – Fabian Lurz Jul 2 '17 at 15:38
1

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? – Fabian Lurz Jul 2 '17 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 Jul 7 '17 at 9:36

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