6

I'm aware of the now keyword that aliases block.timestamp (uint): current block timestamp and the time units

But I fail on finding a way to get the block timestamp of when the contract was mined. Should I use an event and "log" the now keyword into a start variable ?

7

You have to code it into your contract either by saving the block.timestamp in the constructor:

contract A {
  uint public createdTimestamp;
  function A() {
    createdTimestamp = block.timestamp;
  }
}

which you can access like this:

contract B is Test {
  function testTimestamp () {
    A a = new A();
    uint timestamp = a.createdTimestamp();
    //@log timestamp `uint timestamp`
  }
}

or log an event, if you don't need to access this information from within the chain:

contract A {
  event created(uint timestamp);
  function A() {
    created(block.timestamp);
  }
}

But a query for arbitrary contracts is not possible, however this can be achieved in O(log_2 n) with a binary search for contract code.

Your Answer

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

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