3

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?

1 Answer 1

3

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.

2
  • can you explain why block.number * 15? are u assuming a block every 15 seconds?
    – Zaid Amir
    Mar 19, 2018 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 Mar 19, 2018 at 18:09

Your Answer

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

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