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

2 Answers 2

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)

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.

3
  • So is tracking delta of block IDs a better way to track units of time?
    – user22075
    Dec 6, 2017 at 1: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 6, 2017 at 5: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. Jul 29, 2018 at 11:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy