L0vdL0vd

erigon_getBlockByTimestamp

Returns the block closest to a Unix timestamp. The fastest way to turn a date into a block number.

归档 · 可查询任意历史区块

Erigon-specific. Saves the binary search over eth_getBlockByNumber you would otherwise run for every date.

curl https://eth.l0vdinfra.com/YOUR_KEY \
  -X POST \
  -H "Content-Type: application/json" \
  --data '{"jsonrpc":"2.0","id":1,"method":"erigon_getBlockByTimestamp","params":["1704067200",false]}'

响应示例

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "baseFeePerGas": "0x2ea76811a",
    "difficulty": "0x0",
    "extraData": "0xd883010d05846765746888676f312e32312e35856c696e7578",
    "gasLimit": "0x1c9c380",
    "gasUsed": "0xd0638d",
    "hash": "0x08f760c77e7a5843464404bf59d1f042a8b2ec18ae9345a16940546216069eec",
    "logsBloom": "0x0c2f4922c4a154388199420c8a08930a0c11cc41ec800604260dbb0e94725b33300509088ebf538013591f820cd0393d3a83d80abefcb5c30329013b04ad0510387a33cd49028bfa5d1c755e407d346aa4a8108ebc771c42368458acc3a789b37a915aa2…",
    "miner": "0x8a6af67676694aa48acfe4798e23a80feee05bcb",
    "mixHash": "0x699eb6254783829743a754a5397be856bfab0febcdfdb1f529841de19204d981",
    "nonce": "0x0000000000000000",
    "number": "0x12086df",
    "parentHash": "0x2757d9075d142237a41aa35e60e576b663d073674f7982205121a4ce168efbd1",
    "receiptsRoot": "0x9e3f198a9f6c139ac1a6187b2dd762c170bb275c61a0eb43eb534767fd2d9a08",
    "sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
    "size": "0xd581",
    "stateRoot": "0x481de57d7e78c6896b4501183ac291c832ac6e745570951dd98f9aaba46fd20a",
    "timestamp": "0x6592008b",
    "transactions": [
      "0xe7c0bdbc1f72520e46b83e58ee4d636bb15c7db716d23773126ddbe019ea19ad",
      "0x7e9dd039ad4751609c6e5d4e9a1c2ef5e4c407be70bb8a8ff8ef8b5fef48db29"
    ],
    "transactionsRoot": "0x573d7d540ff2489e962aa87c13ce32a1cfc59bbdf8a66d81b649bc0dfb9c1a46",
    "uncles": [],
    "withdrawals": [
      {
        "index": "0x1c980e6",
        "validatorIndex": "0x305ce",
        "address": "0xb9d7934878b5fb9610b3fe8a5e441e8fad7e293f",
        "amount": "0x10b8944"
      },
      {
        "index": "0x1c980e7",
        "validatorIndex": "0x305cf",
        "address": "0xb9d7934878b5fb9610b3fe8a5e441e8fad7e293f",
        "amount": "0x37f48df"
      }
    ],
    "withdrawalsRoot": "0x774fac51d1f9a5cf9483424536f7277d525d63d0e8b34246bb8126f02276bfd9"
  }
}

示例中较长的数组和十六进制字符串已截断。

参数与您的端点

参数

timestampstring必填
Unix time in seconds, as a decimal string, e.g. "1704067200" for 2024-01-01 00:00 UTC.
fullTransactionsboolean必填
true for full transaction objects, false for hashes.

返回值

object Block object.

numberstring
Block number, hex.
hashstring
Block hash.
parentHashstring
Hash of the parent block.
timestampstring
Unix timestamp, hex.
minerstring
Fee recipient address.
gasUsedstring
Total gas used by the block's transactions, hex.
gasLimitstring
Block gas limit, hex.
baseFeePerGasstring
EIP-1559 base fee, hex wei (London and later).
transactionsarray
Transaction hashes, or full transaction objects when the second parameter is true.
logsBloomstring
Bloom filter for the block's logs.
stateRootstring
Root of the state trie after the block.

适用场景

Turn a date into a block in one call: end-of-month balances, the state at a report date, the block when an incident started.

如何解读结果

A normal block object. Compare its timestamp to yours: it is the block closest to the requested time.

提示

  • Pair it with eth_getBalance or eth_call at the returned number to read history by date.
  • Timestamps are seconds, not milliseconds: Date.now() / 1000 in JavaScript.

相关方法