I see many warnings against the use of now (block.timestamp) in solidity code but no one mentions any alternative of getting the time. What is the alternative of using now?

| improve this question | | | | |

The main issue with using block.timestamp is that it is manipulable by miners and random fluctuations to within an hour or so. For minute-scale time, you should use block.number * 15, which also can fluctuate but is less arbitrarily manipulable.

On the scale of days or more, block.timestamp will be far more accurate, since it is tied to real unix time.

| improve this answer | | | | |
  • can you explain why block.number * 15? are u assuming a block every 15 seconds? – Zaid Amir Mar 19 '18 at 14:56
  • Yes, on average. It's actually more like 14 now, but regardless it's actually random so you're not going to get great accuracy – Tjaden Hess Mar 19 '18 at 18:09

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.