{"eip":234,"title":"Add `blockHash` to JSON-RPC filter options.","description":"Add an option to JSON-RPC filter options (used by ethnewFilter and ethgetLogs) that allows specifying the block hash that should be included in the results. This option would be an alternative to fromBlock/toBlock options.","authors":["Micah Zoltu (@MicahZoltu)"],"status":"Final","type":"Standards Track","category":"Interface","created":"2017-03-24","requires":[1474],"discussionsTo":"https://github.com/ethereum/EIPs/issues/234","repo":"EIPs","label":"EIP-234","officialUrl":"https://eips.ethereum.org/EIPS/eip-234","sourceUrl":"https://github.com/ethereum/EIPs/blob/master/EIPS/eip-234.md","url":"https://eips.huatuo.xyz/eip-234/","tldr":{"en":"Adds a blockHash option to eth_getLogs and eth_newFilter, so apps can fetch logs for one exact block and stay correct through chain reorganizations.","ja":"eth_getLogs と eth_newFilter に blockHash オプションを追加し、アプリが特定の 1 ブロックのログを取得して、チェーンの再編成（reorg）があっても正確さを保てるようにする。","ko":"eth_getLogs와 eth_newFilter에 blockHash 옵션을 추가해, 앱이 정확히 하나의 블록에 대한 로그를 가져오고 체인 재구성(reorg)에도 올바르게 동작하게 한다.","zh":"为 eth_getLogs 和 eth_newFilter 增加 blockHash 选项，使应用可以获取某个确切区块的日志，并在链重组时保持正确。"},"tags":["json-rpc","logs","reorg","interface"],"explainers":{"en":{"lang":"en","tldr":"Adds a blockHash option to eth_getLogs and eth_newFilter, so apps can fetch logs for one exact block and stay correct through chain reorganizations.","tags":["json-rpc","logs","reorg","interface"],"related":[1474,1898],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-234/","markdown":"## What problem does it solve?\n\nApps that index events, such as wallets, exchanges and dashboards, need to know both when logs appear and when a reorg removes them. Log subscriptions alone are fragile. If your WebSocket drops or the node restarts during a reorg, you never hear about the removed logs.\n\nA robust pattern is to track blocks yourself and fetch logs block by block. Before EIP-234, though, `eth_getLogs` only accepted block **numbers**. If a reorg happened between \"I saw block #100 with hash 0xabc\" and \"give me logs for #100\", you could silently get logs from a different block #100. If the result was empty, you could not even tell which block it came from.\n\n## How it works\n\nThe filter object for `eth_getLogs` and `eth_newFilter` gets an optional `blockHash` field:\n\n- The node returns the logs that match the filter **in exactly that block**, whether or not the block is still on the canonical chain.\n- If the node does not know the hash, it returns an **error** rather than an empty list. The spec's test case uses code `-32000` with message `\"Block not found.\"`.\n- `blockHash` is mutually exclusive with `fromBlock` / `toBlock`.\n- `address` and `topics` filtering work as usual.\n\nNow an empty result really means \"this block had no matching logs\", and an error means \"roll back and resync\".\n\n## Sample code\n\nRaw JSON-RPC:\n\n```json\n{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"eth_getLogs\",\n  \"params\": [{\n    \"blockHash\": \"0x\u003c32-byte block hash\u003e\",\n    \"address\": \"0x\u003ccontract address\u003e\",\n    \"topics\": [\"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef\"]\n  }]\n}\n```\n\nThe topic above is `keccak256(\"Transfer(address,address,uint256)\")`.\n\nethers v6, fetching logs for a block you already saw:\n\n```ts\nimport { JsonRpcProvider, id } from \"ethers\";\n\nconst provider = new JsonRpcProvider(process.env.RPC_URL);\n\nprovider.on(\"block\", async (n: number) =\u003e {\n  const block = await provider.getBlock(n);\n  try {\n    const logs = await provider.getLogs({\n      blockHash: block!.hash!,                     // pin to this exact block\n      topics: [id(\"Transfer(address,address,uint256)\")],\n    });\n    console.log(n, block!.hash, logs.length);\n  } catch {\n    // block vanished in a reorg: roll back local state and resync\n  }\n});\n```\n\n## Things to know\n\n- This EIP is **Final** and supported by major clients. The spec lists Geth as the reference implementation.\n- It depends on [EIP-1474](/eip-1474/), the JSON-RPC spec EIP, which is Stagnant. The canonical RPC definition now lives in the `ethereum/execution-apis` repository.\n- [EIP-1898](/eip-1898/) applies the same idea to state queries such as `eth_call` and `eth_getBalance`, letting you pin them to a block hash.\n- Combine with a block's `logsBloom` to skip `eth_getLogs` calls for blocks that cannot contain your events.\n"},"ja":{"lang":"ja","tldr":"eth_getLogs と eth_newFilter に blockHash オプションを追加し、アプリが特定の 1 ブロックのログを取得して、チェーンの再編成（reorg）があっても正確さを保てるようにする。","tags":["json-rpc","logs","reorg","interface"],"related":[1474,1898],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-234/","markdown":"## 何を解決するのか\n\nウォレット、取引所、ダッシュボードのように、イベントをインデックスするアプリは、ログがいつ現れるかだけでなく、reorg でいつ消えるかも知る必要があります。ログのサブスクリプションだけでは脆弱です。reorg の最中に WebSocket が切れたりノードが再起動したりすると、削除されたログについて通知を受け取れません。\n\n堅牢なパターンは、自分でブロックを追跡し、ブロックごとにログを取得することです。しかし EIP-234 以前は、`eth_getLogs` が受け付けるのブロック**番号**だけでした。「ハッシュ 0xabc のブロック #100 を見た」から「#100 のログをください」までの間に reorg が起きると、別のブロック #100 のログが気づかないうちに返される可能性がありました。結果が空の場合は、どのブロックの結果なのかさえ分かりませんでした。\n\n## 仕組み\n\n`eth_getLogs` と `eth_newFilter` のフィルターオブジェクトに、任意の `blockHash` フィールドが追加されます。\n\n- ノードは、そのブロックがまだ正規チェーン上にあるかどうかにかかわらず、**ちょうどそのブロック内で**フィルターに一致するログを返します。\n- ノードがそのハッシュを知らない場合は、空のリストではなく**エラー**を返します。仕様書のテストケースでは、コード `-32000` とメッセージ `\"Block not found.\"` を使っています。\n- `blockHash` は `fromBlock` / `toBlock` と同時には指定できません。\n- `address` と `topics` によるフィルタリングは通常どおり動作します。\n\nこれにより、空の結果は本当に「このブロックに一致するログはなかった」という意味になり、エラーは「ロールバックして再同期する」という意味になります。\n\n## サンプルコード\n\n生の JSON-RPC:\n\n```json\n{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"eth_getLogs\",\n  \"params\": [{\n    \"blockHash\": \"0x\u003c32-byte block hash\u003e\",\n    \"address\": \"0x\u003ccontract address\u003e\",\n    \"topics\": [\"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef\"]\n  }]\n}\n```\n\n上記の topic は `keccak256(\"Transfer(address,address,uint256)\")` です。\n\nethers v6 で、すでに見たブロックのログを取得する例:\n\n```ts\nimport { JsonRpcProvider, id } from \"ethers\";\n\nconst provider = new JsonRpcProvider(process.env.RPC_URL);\n\nprovider.on(\"block\", async (n: number) =\u003e {\n  const block = await provider.getBlock(n);\n  try {\n    const logs = await provider.getLogs({\n      blockHash: block!.hash!,                     // pin to this exact block\n      topics: [id(\"Transfer(address,address,uint256)\")],\n    });\n    console.log(n, block!.hash, logs.length);\n  } catch {\n    // block vanished in a reorg: roll back local state and resync\n  }\n});\n```\n\n## 知っておくべきこと\n\n- この EIP は **Final** で、主要なクライアントがサポートしています。仕様書は参照実装として Geth を挙げています。\n- JSON-RPC 仕様の EIP である [EIP-1474](/eip-1474/) に依存していますが、こちらは Stagnant です。正式な RPC 定義は現在 `ethereum/execution-apis` リポジトリにあります。\n- [EIP-1898](/eip-1898/) は同じ考え方を `eth_call` や `eth_getBalance` などのステートクエリに適用し、ブロックハッシュに固定できるようにします。\n- ブロックの `logsBloom` と組み合わせると、目的のイベントを含み得ないブロックについて `eth_getLogs` の呼び出しを省略できます。\n"},"ko":{"lang":"ko","tldr":"eth_getLogs와 eth_newFilter에 blockHash 옵션을 추가해, 앱이 정확히 하나의 블록에 대한 로그를 가져오고 체인 재구성(reorg)에도 올바르게 동작하게 한다.","tags":["json-rpc","logs","reorg","interface"],"related":[1474,1898],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-234/","markdown":"## 어떤 문제를 해결하나요?\n\n지갑, 거래소, 대시보드처럼 이벤트를 인덱싱하는 앱은 로그가 언제 나타나는지뿐 아니라 reorg로 언제 사라지는지도 알아야 합니다. 로그 구독만으로는 취약합니다. reorg 중에 WebSocket 연결이 끊기거나 노드가 재시작되면, 제거된 로그에 대한 알림을 받지 못합니다.\n\n견고한 방식은 블록을 직접 추적하면서 블록 단위로 로그를 가져오는 것입니다. 하지만 EIP-234 이전에는 `eth_getLogs`가 블록 **번호**만 받았습니다. \"해시가 0xabc인 블록 #100을 봤다\"와 \"#100의 로그를 달라\" 사이에 reorg가 일어나면, 다른 블록 #100의 로그가 조용히 반환될 수 있었습니다. 결과가 비어 있으면 어느 블록에서 온 결과인지조차 알 수 없었습니다.\n\n## 어떻게 동작하나요?\n\n`eth_getLogs`와 `eth_newFilter`의 필터 객체에 선택적 `blockHash` 필드가 추가됩니다.\n\n- 노드는 그 블록이 아직 정규 체인에 있는지와 상관없이, **정확히 그 블록 안에서** 필터와 일치하는 로그를 반환합니다.\n- 노드가 해당 해시를 모르면 빈 리스트 대신 **에러**를 반환합니다. 명세서의 테스트 케이스는 코드 `-32000`과 메시지 `\"Block not found.\"`를 사용합니다.\n- `blockHash`는 `fromBlock` / `toBlock`과 함께 쓸 수 없습니다.\n- `address`와 `topics` 필터링은 평소처럼 동작합니다.\n\n이제 빈 결과는 정말로 \"이 블록에는 일치하는 로그가 없었다\"는 뜻이고, 에러는 \"롤백하고 다시 동기화하라\"는 뜻입니다.\n\n## 샘플 코드\n\n원시 JSON-RPC:\n\n```json\n{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"eth_getLogs\",\n  \"params\": [{\n    \"blockHash\": \"0x\u003c32-byte block hash\u003e\",\n    \"address\": \"0x\u003ccontract address\u003e\",\n    \"topics\": [\"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef\"]\n  }]\n}\n```\n\n위의 topic은 `keccak256(\"Transfer(address,address,uint256)\")`입니다.\n\nethers v6로, 이미 본 블록의 로그 가져오기:\n\n```ts\nimport { JsonRpcProvider, id } from \"ethers\";\n\nconst provider = new JsonRpcProvider(process.env.RPC_URL);\n\nprovider.on(\"block\", async (n: number) =\u003e {\n  const block = await provider.getBlock(n);\n  try {\n    const logs = await provider.getLogs({\n      blockHash: block!.hash!,                     // pin to this exact block\n      topics: [id(\"Transfer(address,address,uint256)\")],\n    });\n    console.log(n, block!.hash, logs.length);\n  } catch {\n    // block vanished in a reorg: roll back local state and resync\n  }\n});\n```\n\n## 알아둘 점\n\n- 이 EIP는 **Final** 상태이며 주요 클라이언트가 지원합니다. 명세서는 참조 구현으로 Geth를 꼽습니다.\n- JSON-RPC 명세 EIP인 [EIP-1474](/eip-1474/)에 의존하는데, 이쪽은 Stagnant 상태입니다. 정식 RPC 정의는 현재 `ethereum/execution-apis` 저장소에 있습니다.\n- [EIP-1898](/eip-1898/)은 같은 아이디어를 `eth_call`, `eth_getBalance` 같은 상태 쿼리에 적용해, 블록 해시에 고정할 수 있게 합니다.\n- 블록의 `logsBloom`과 함께 쓰면, 원하는 이벤트가 들어 있을 수 없는 블록에 대해 `eth_getLogs` 호출을 건너뛸 수 있습니다.\n"},"zh":{"lang":"zh","tldr":"为 eth_getLogs 和 eth_newFilter 增加 blockHash 选项，使应用可以获取某个确切区块的日志，并在链重组时保持正确。","tags":["json-rpc","logs","reorg","interface"],"related":[1474,1898],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-234/","markdown":"## 它解决什么问题？\n\n钱包、交易所和仪表盘等索引事件的应用，既需要知道日志何时出现，也需要知道重组何时把它们移除。仅靠日志订阅是脆弱的。如果在重组期间 WebSocket 断开或节点重启，你就永远收不到关于日志被移除的通知。\n\n一种稳健的做法是自己跟踪区块，并逐个区块获取日志。但在 EIP-234 之前，`eth_getLogs` 只接受区块**编号**。如果在\"我看到了哈希为 0xabc 的区块 #100\"和\"给我 #100 的日志\"之间发生了重组，你可能会在不知情的情况下得到另一个区块 #100 的日志。如果结果为空，你甚至无法判断它来自哪个区块。\n\n## 它如何运作\n\n`eth_getLogs` 和 `eth_newFilter` 的过滤器对象新增一个可选的 `blockHash` 字段：\n\n- 无论该区块是否仍在规范链上，节点都会返回**恰好在该区块内**匹配过滤器的日志。\n- 如果节点不认识该哈希，它会返回**错误**，而不是空列表。规范的测试用例使用错误码 `-32000` 和消息 `\"Block not found.\"`。\n- `blockHash` 与 `fromBlock` / `toBlock` 互斥。\n- `address` 和 `topics` 的过滤照常工作。\n\n现在，空结果真正意味着\"这个区块没有匹配的日志\"，而错误则意味着\"回滚并重新同步\"。\n\n## 示例代码\n\n原始 JSON-RPC：\n\n```json\n{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"eth_getLogs\",\n  \"params\": [{\n    \"blockHash\": \"0x\u003c32-byte block hash\u003e\",\n    \"address\": \"0x\u003ccontract address\u003e\",\n    \"topics\": [\"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef\"]\n  }]\n}\n```\n\n上面的 topic 是 `keccak256(\"Transfer(address,address,uint256)\")`。\n\n使用 ethers v6，为你已经见过的区块获取日志：\n\n```ts\nimport { JsonRpcProvider, id } from \"ethers\";\n\nconst provider = new JsonRpcProvider(process.env.RPC_URL);\n\nprovider.on(\"block\", async (n: number) =\u003e {\n  const block = await provider.getBlock(n);\n  try {\n    const logs = await provider.getLogs({\n      blockHash: block!.hash!,                     // pin to this exact block\n      topics: [id(\"Transfer(address,address,uint256)\")],\n    });\n    console.log(n, block!.hash, logs.length);\n  } catch {\n    // block vanished in a reorg: roll back local state and resync\n  }\n});\n```\n\n## 需要注意\n\n- 这个 EIP 的状态是 **Final**，并得到主要客户端的支持。规范把 Geth 列为参考实现。\n- 它依赖于 JSON-RPC 规范 EIP [EIP-1474](/eip-1474/)，后者的状态是 Stagnant。规范的 RPC 定义现在位于 `ethereum/execution-apis` 仓库。\n- [EIP-1898](/eip-1898/) 把同样的思路应用到 `eth_call` 和 `eth_getBalance` 等状态查询上，让你可以将它们固定到某个区块哈希。\n- 可以结合区块的 `logsBloom`，对不可能包含你所关注事件的区块跳过 `eth_getLogs` 调用。\n"}},"requiredBy":[1898]}
