monosux/ethereum-block-by-date

Getting Date by Block

Closed this issue · 1 comments

Thanks for this great package. I've got a bunch of blocks and wondering if there is a method to get the date by block, rather than block by date?

Hi @rvmelkonian,

that is easy, web3 has the 'getBlock()' function, it returns information about the needed block, including blocks timestamp. Take a look: https://web3js.readthedocs.io/en/v1.2.11/web3-eth.html#getblock

web3.eth.getBlock(3150)
.then(console.log);

// will return:

{
   ...
    "timestamp": 1429287689,
   ...
}