6

I'm looking at KittyBreeding.sol and see

 /// @dev Set the cooldownEndTime for the given Kitty, based on its current cooldownIndex.
    ///  Also increments the cooldownIndex (unless it has hit the cap).
    /// @param _kitten A reference to the Kitty in storage which needs its timer started.
    function _triggerCooldown(Kitty storage _kitten) internal {
        // Compute the end of the cooldown time (based on current cooldownIndex)
        _kitten.cooldownEndTime = uint64(now + cooldowns[_kitten.cooldownIndex]);

but I don't see where "now" is defined, except in their kitty-core.test.js

How does this DAPP track time, which lets the website show timers?

2 Answers2

8

now is a Solidity special variable, which equates to the current time since the epoch, in seconds.

From the documentation (linked above):

now (uint): current block timestamp (alias for block.timestamp)

Richard Horrocks
  • 37,835
  • 13
  • 87
  • 144
4

It's worth noting that miners can manipulate now and so it shouldn't be relied upon for anything sensitive such as seeding Psuedo-Random Number Generators.

Luke
  • 61
  • 1
  • 1
  • 5
  • So is tracking delta of block IDs a better way to track units of time? –  Dec 06 '17 at 01:35
  • Agree with Ismael's review but moderators need to be careful about affecting reputation, so even converting this into a comment might be interfering too much. Will leave as is. – eth Dec 06 '17 at 05:01
  • @quantumpotato It is more secure, as it's harder to game. Btw, here's a real-world scenario where an on-chain Pseudo-Random Number Generator was implemented. It enabled a deterministic trapdoor. – Paul Razvan Berg Jul 29 '18 at 11:23