[alethzero] is it possible to get the most recent block's timestamp via JS?

I'd like to check a timestamp in a contract against the timestamp of the most recent block via JavaScript in AlethZero.

Is it possible to query the most recent block's timestamp at present? If not is there any strategy for checking this indirectly?

Comments

  • mids106mids106 Member Posts: 188 ✭✭✭
    Maybe; With the JSONRPC interface you can simply call lastBlock, but that isn't exposed through the JavaScript API.

    You can use eth.getTransactions (POC5) or get.getMessages to get the most recent block that contained any transactions, but it doesn't seem to return any that don't.

    An alternative might be to register a callback with eth.newBlock and use the javascript timestamp when it gets called. In POC6 this would be eth.watchChain
  • robmyersrobmyers Member Posts: 65 ✭✭✭
    Thank you! I misunderstood getTransactions() to be referring to a specific account. I guess on the live blockchain that there will be enough transactions that it will keep relatively up to date with the current block.

    I'll try eth.newBlock().

    Can lastBlock be exposed through the POC6 JS API or is that now frozen?
Sign In or Register to comment.