L0vdL0vd

eth_getLogs

Returns all logs (events) that match a filter over a block range.

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

A very large range or result can be rejected with error -32005. Split big backfills into chunks of about 1,000 blocks (10 on the free test key) and run them in parallel within your RPS cap.

curl https://eth.l0vdinfra.com/YOUR_KEY \
  -X POST \
  -H "Content-Type: application/json" \
  --data '{"jsonrpc":"2.0","id":1,"method":"eth_getLogs","params":[{"fromBlock":"0x1208a5f","toBlock":"0x1208a5f","address":"0xdAC17F958D2ee523a2206206994597C13D831ec7","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"]}]}'

响应示例

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": [
    {
      "address": "0xdac17f958d2ee523a2206206994597c13d831ec7",
      "topics": [
        "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
        "0x000000000000000000000000c926253bd109f81c6ea41e452a7db19d322dba09"
      ],
      "data": "0x00000000000000000000000000000000000000000000000000000000602c3570",
      "blockNumber": "0x1208a5f",
      "transactionHash": "0xb235be710eea360b4f7b5f1395b0d4e9b3f0761968fffd06977ce7d82c99cb0d",
      "transactionIndex": "0xc",
      "blockHash": "0xc7a2fd354a9a1512636dad41b44e618905f5e8d2500f08c515c3bbbdf5261f6a",
      "logIndex": "0x3",
      "removed": false,
      "blockTimestamp": "0x65922b33"
    },
    {
      "address": "0xdac17f958d2ee523a2206206994597c13d831ec7",
      "topics": [
        "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
        "0x00000000000000000000000030a73bc3d0adea47638f5fb8c029ad4fe97a4f15"
      ],
      "data": "0x0000000000000000000000000000000000000000000000000000000055d4a800",
      "blockNumber": "0x1208a5f",
      "transactionHash": "0x09fe500dd787c5d1f4b123e82c86e6d4bbf003310b24e2cebb47c00076d43549",
      "transactionIndex": "0x12",
      "blockHash": "0xc7a2fd354a9a1512636dad41b44e618905f5e8d2500f08c515c3bbbdf5261f6a",
      "logIndex": "0x4",
      "removed": false,
      "blockTimestamp": "0x65922b33"
    }
  ]
}

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

参数与您的端点

参数

filterobject必填
fromBlock and toBlock (hex or tag), address (one address or a list), topics (up to four positions; each a topic, a list of alternatives or null), or blockHash instead of the range.

返回值

array Matching log objects.

addressstring
Contract that emitted the log.
topicsarray
Up to four indexed topics; topic 0 is the event signature hash.
datastring
Non-indexed event arguments, ABI-encoded.
blockNumberstring
Block number, hex.
transactionHashstring
Hash of the transaction that emitted the log.
logIndexstring
Position of the log in the block, hex.
removedboolean
true if the log was removed by a reorg.

适用场景

Fetch events emitted by contracts over a block range: token transfers, swaps, mints, governance votes.

This is the backbone of indexers and backfills: scan history once, then follow new blocks.

如何解读结果

Each log has the emitting address, up to four topics and data. topics[0] is keccak256 of the event signature; indexed arguments follow in topics[1..3]; the rest is ABI-encoded in data.

Decode with the event ABI: viem decodeEventLog, ethers Interface.parseLog, web3.py contract.events.Transfer().process_log.

提示

  • Always filter by address and topics[0]. Unfiltered ranges return huge payloads.
  • Walk long histories in chunks of about 1,000 blocks, and halve the chunk when you get error -32005 (too many results). The free test key allows 10 blocks per request; paid plans don't have this limit.
  • Run chunks in parallel up to your RPS cap; on L0vd you pay a flat price, so a full backfill costs nothing extra.
  • Use blockHash instead of a range to read one block's logs consistently during reorgs.

相关方法