根据时间获取区块高度#
查询距指定时间最近的区块高度,可通过 closest 参数指定取早于(before)或晚于(after)该时间的最近区块。
支持的链:见获取区块 API 支持的链(apiName:block-height-by-time)。
请求地址#
GET
https://web3.okx.com/api/v6/explorer/block/block-height-by-time请求参数#
| 参数名 | 类型 | 是否必填 | 描述 |
|---|---|---|---|
| chainIndex | String | 是 | 链唯一标识,如 ETH 为 1、BTC 为 0;支持范围见获取区块 API 支持的链 |
| time | String | 是 | 具体时间;Unix 时间戳的毫秒数格式,如 1597026383085 |
| closest | String | 否 | 取值 before 或 after,默认 before:before 返回早于(含)指定时间的最近区块,after 返回晚于指定时间的最近区块 |
响应参数#
| 参数名 | 类型 | 描述 |
|---|---|---|
| height | String | 距指定时间最近(按 closest 方向)的区块高度 |
| blockTime | String | 该区块的出块时间;Unix 时间戳的毫秒数格式,如 1597026383085 |
请求示例#
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'
响应示例#
json
{
"code": "0",
"msg": "",
"data": [
{
"height": "19000000",
"blockTime": "1705146239000"
}
]
}
