Skip to main content
Version: 2.2

Get block by date

Don't have an API key yet?

Start using this API for your project today.

Get your free API key
GEThttps://deep-index.moralis.io/api/v2.2/dateToBlock

Get the closest block given the date.

QUERY PARAMS
chainstring
The chain to query
datestringrequired
Unix date in seconds or a datestring (any format that is accepted by momentjs)
Responses
API KEY
import Moralis from 'moralis';

try {
await Moralis.start({
apiKey: "YOUR_API_KEY"
});

const response = await Moralis.EvmApi.block.getDateToBlock({
"chain": "0x1"
});

console.log(response.raw);
} catch (e) {
console.error(e);
}
Response Example
{
"date": "2020-01-01T00:00:00+00:00",
"block": 9193266,
"timestamp": 1577836811,
"block_timestamp": "2019-12-31T23:59:45.000Z",
"hash": "0x9b559aef7ea858608c2e554246fe4a24287e7aeeb976848df2b9a2531f4b9171",
"parent_hash": "0x011d1fc45839de975cc55d758943f9f1d204f80a90eb631f3bf064b80d53e045"
}