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
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.
-
can you explain why
block.number * 15
? are u assuming a block every 15 seconds? 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