Skip to main content

Don't have an API key yet?

Sign-up to Moralis to get your free API key and start building today.

Get Your Free API Key
Version: 2.0

Get block by date

GEThttps://deep-index.moralis.io/api/v2/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"
}