<
 
 
 
 
×
>
hide You are viewing an archived web page, collected at the request of Ethereum Foundation using Archive-It. This page was captured on 16:10:21 Jun 05, 2021 , and is part of the Community collection. The information on this web page may be out of date. See All versions of this archived page. Loading media information

[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.