Get Block Height by Time#
Retrieve the block height closest to a specified time. Use the closest parameter to select the nearest block before or after that time.
Supported chains: see Get Block API Supported Chains (apiName: block-height-by-time).
Request URL#
GET
https://web3.okx.com/api/v6/explorer/block/block-height-by-timeRequest Parameters#
| Parameter | Type | Required | Description |
|---|---|---|---|
| chainIndex | String | Yes | Unique identifier of the chain, e.g., 1 for ETH, 0 for BTC. See Get Block API Supported Chains for supported values. |
| time | String | Yes | Target time, as a Unix timestamp in milliseconds, e.g., 1597026383085. |
| closest | String | No | Either before or after, defaults to before. before returns the nearest block at or before the specified time; after returns the nearest block after the specified time. |
Response Parameters#
| Parameter | Type | Description |
|---|---|---|
| height | String | Height of the block closest to the specified time, in the direction given by closest. |
| blockTime | String | Block time of that block, as a Unix timestamp in milliseconds, e.g., 1597026383085. |
Request Example#
shell
curl --location --request GET 'https://web3.okx.com/api/v6/explorer/block/block-height-by-time?chainIndex=1&time=1705146239000&closest=before' \
--header 'OK-ACCESS-KEY: 37c541a1-****-****-****-10fe7a038418' \
--header 'OK-ACCESS-SIGN: leaV********3uw=' \
--header 'OK-ACCESS-PASSPHRASE: 1****6' \
--header 'OK-ACCESS-TIMESTAMP: 2023-10-18T12:21:41.274Z'
Response Example#
json
{
"code": "0",
"msg": "",
"data": [
{
"height": "19000000",
"blockTime": "1705146239000"
}
]
}
