"block.timestamp" and "now" are known. I would like to know how to get a timestamp of a specified block.number?

Like: uint blockDoneTime = (block.number - 1000).now; // Or something like this...? :)

  • 1
    Welcome to the Ethereum Stack Exchange! I've attempted an answer but this question might be an XY problem.
    – eth
    Aug 27 '17 at 10:05
  • 1
    There's the EIP github.com/ethereum/EIPs/pull/210 which proposes accessing the blockchain data through a contract.
    – Ismael
    Aug 27 '17 at 23:28

As user eth correctly indicated, you cannot get the timestamp of arbitrary blocks directly.

One work around is to you pull in data via external service providers and reading them via oracles. You could, e.g. use the etherscan API and then use a simple oraclize.it query to trustlessly load the data into your contract.

A lot more cumbersome, costly and involved than what you had in mind but IMO the best you can do.

Theoretically you could feed in a lot of full blocks to the smart contract, validate the required parts of the chain to make sure that the data is not fake. Both the required amounts of data and the computational complexity would probably make this pretty much impossible in practise.


Solidity is one of the higher level languages for the EVM. The EVM and the blockchain are different, and the EVM has limited access to the blockchain: What OPCODES are available for the Ethereum EVM?

If your contract wants to know information about 1000 blocks ago, you need to store that data in your contract (maybe as part of initializing the contract). Alternatively, if your contract was invoked 1000 blocks ago, that's when it should have stored the timestamp.

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.