We're working on a smart contract in which certain transactions are executed every time a certain token price point is crossed. Therefore, if in a given instant the price crosses a set point more than 10 times, we don't wanna execute every transaction and pay transaction and gas fees. It would make sense only to execute the last transaction in every instant of time (say every 4 hours). Is there a way to do this in the smart contract or Metamask integration level so that all the redundant preceding transactions are cancelled and only the latest transaction in a given instant of time is executed?

We also wanna make sure that at the time of execution, the transactions happen with original values and not the new ones that were updated in the timespan following the original transaction creation.

1 Answer 1


Yes, there is a Unit Called 'Hours' in solidity. See these docs:


Just add a require statement into the function to check if block.timestamp of now, which gives the current block 'time', is 4 hours more than the previous transaction's block time.

NOTE: When doing this you will need to store when a transaction is made. So for example in the transaction function have something like: 'uint256 timeSent=block.timestamp as well ")

  • 1
    Thanks for sharing this. Hopefully helps us with the conditional execution.
    – Samarth
    Nov 17, 2021 at 9:07

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.