I was unable to find any relevant documentation for the now keyword within the Solidity documentation, other than its usage in examples. What exactly does the now keyword return, how is it determined and what are the associated gas costs? I assume it is similar to Unix time.
Asked
Active
Viewed 1.2k times
17
Michael
- 1,065
- 2
- 9
- 8
-
Related: https://ethereum.stackexchange.com/questions/15747/what-is-the-difference-between-now-and-block-timestamp/15748#15748 – Richard Horrocks Jul 04 '17 at 10:17
1 Answers
22
In short now is just an alias for block.timestamp and it is the number of seconds since the Epoch as per documentation.
Beware that this value is set by miners so there is a little potential for a malicious manipulation but general nodes are meant to coordinate.
EDIT (17 Jan 2024):
now has been deprecated post version 0.7.0.
Note: In version 0.7.0, the alias now (for block.timestamp) was removed.
sayandcode
- 107
- 3
Jakub Wojciechowski
- 6,399
- 4
- 18
- 16
-
6Update: Solidity 0.7.0 deprecated the
nowkeyword. For contracts ^0.7.0, you must useblock.timestamp. – Shane Fontaine Jul 01 '20 at 16:51 -
It's worth noting that miners can manipulate block.timestamp & the old 'now' keyword. You can't rely on timestamp, previous block number hash, difficulty, etc because miners can exploit this to call your function with parameters that result in them winning / knowing random number outcome. – Nerdi.org Dec 25 '22 at 05:57