0

Say I want to do a simple operation where a value x is automatically doubled after 1 hour. I want the contract to automatically check that it is time to double the value without needing to explicitly call a function that checks time, nor using a loop (which would quickly consume all the gas).

Since solidity is event-driven, the best solution seems to compute what would have happened in the time span, the next time an event is triggered.

However, that makes it impossible to manage some applications that would be trivial in traditional, gasless programming. Say I want a landlord contract to automatically give tenants 10 days at the beginning of each month to pay their rent. From what I understand, it is plainly impossible to do unless the landlord manually triggers the start of the payment period each month.

At the same time, I have seen some applications, such as reverse Dutch auctions which require the price to increment at regular intervals of time, with the bidders having some limited time to bid https://twitter.com/IDOLaunchpad/status/1439991103642550279

How would time be managed in such an application?

2
  • It could be implemented as you mentioned, every time an actions is performed (a bid) the contract will update the time before processing it.
    – Ismael
    Commented Sep 23, 2021 at 6:15
  • 1
    Thank you! Someone on discord provided some additional ideas: "That is correct: there are no “lifecycle hooks” in Solidity/Ethereum, unlike say Substrate/Polkadot. Also, Ethereum prefers “pulls” vs “pushes” in contract design, because pushes tend to be risky (more info: fravoll.github.io/solidity-patterns/pull_over_push.html)".
    – Nassim
    Commented Sep 24, 2021 at 17:40

0

Your Answer

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

Browse other questions tagged or ask your own question.