---
eip: 234
label: EIP-234
title: Add `blockHash` to JSON-RPC filter options.
status: Final
type: Standards Track
category: Interface
created: 2017-03-24
requires: 1474
official: https://eips.ethereum.org/EIPS/eip-234
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-234.md
canonical: https://eips.huatuo.xyz/ko/eip-234/
lang: ko
tldr: eth_getLogs와 eth_newFilter에 blockHash 옵션을 추가해, 앱이 정확히 하나의 블록에 대한 로그를 가져오고 체인 재구성(reorg)에도 올바르게 동작하게 한다.
tags: [json-rpc, logs, reorg, interface]
---

# EIP-234: Add `blockHash` to JSON-RPC filter options.

> 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.

**TL;DR:** eth_getLogs와 eth_newFilter에 blockHash 옵션을 추가해, 앱이 정확히 하나의 블록에 대한 로그를 가져오고 체인 재구성(reorg)에도 올바르게 동작하게 한다.

## 어떤 문제를 해결하나요?

지갑, 거래소, 대시보드처럼 이벤트를 인덱싱하는 앱은 로그가 언제 나타나는지뿐 아니라 reorg로 언제 사라지는지도 알아야 합니다. 로그 구독만으로는 취약합니다. reorg 중에 WebSocket 연결이 끊기거나 노드가 재시작되면, 제거된 로그에 대한 알림을 받지 못합니다.

견고한 방식은 블록을 직접 추적하면서 블록 단위로 로그를 가져오는 것입니다. 하지만 EIP-234 이전에는 `eth_getLogs`가 블록 **번호**만 받았습니다. "해시가 0xabc인 블록 #100을 봤다"와 "#100의 로그를 달라" 사이에 reorg가 일어나면, 다른 블록 #100의 로그가 조용히 반환될 수 있었습니다. 결과가 비어 있으면 어느 블록에서 온 결과인지조차 알 수 없었습니다.

## 어떻게 동작하나요?

`eth_getLogs`와 `eth_newFilter`의 필터 객체에 선택적 `blockHash` 필드가 추가됩니다.

- 노드는 그 블록이 아직 정규 체인에 있는지와 상관없이, **정확히 그 블록 안에서** 필터와 일치하는 로그를 반환합니다.
- 노드가 해당 해시를 모르면 빈 리스트 대신 **에러**를 반환합니다. 명세서의 테스트 케이스는 코드 `-32000`과 메시지 `"Block not found."`를 사용합니다.
- `blockHash`는 `fromBlock` / `toBlock`과 함께 쓸 수 없습니다.
- `address`와 `topics` 필터링은 평소처럼 동작합니다.

이제 빈 결과는 정말로 "이 블록에는 일치하는 로그가 없었다"는 뜻이고, 에러는 "롤백하고 다시 동기화하라"는 뜻입니다.

## 샘플 코드

원시 JSON-RPC:

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "eth_getLogs",
  "params": [{
    "blockHash": "0x<32-byte block hash>",
    "address": "0x<contract address>",
    "topics": ["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"]
  }]
}
```

위의 topic은 `keccak256("Transfer(address,address,uint256)")`입니다.

ethers v6로, 이미 본 블록의 로그 가져오기:

```ts
import { JsonRpcProvider, id } from "ethers";

const provider = new JsonRpcProvider(process.env.RPC_URL);

provider.on("block", async (n: number) => {
  const block = await provider.getBlock(n);
  try {
    const logs = await provider.getLogs({
      blockHash: block!.hash!,                     // pin to this exact block
      topics: [id("Transfer(address,address,uint256)")],
    });
    console.log(n, block!.hash, logs.length);
  } catch {
    // block vanished in a reorg: roll back local state and resync
  }
});
```

## 알아둘 점

- 이 EIP는 **Final** 상태이며 주요 클라이언트가 지원합니다. 명세서는 참조 구현으로 Geth를 꼽습니다.
- JSON-RPC 명세 EIP인 [EIP-1474](/eip-1474/)에 의존하는데, 이쪽은 Stagnant 상태입니다. 정식 RPC 정의는 현재 `ethereum/execution-apis` 저장소에 있습니다.
- [EIP-1898](/eip-1898/)은 같은 아이디어를 `eth_call`, `eth_getBalance` 같은 상태 쿼리에 적용해, 블록 해시에 고정할 수 있게 합니다.
- 블록의 `logsBloom`과 함께 쓰면, 원하는 이벤트가 들어 있을 수 없는 블록에 대해 `eth_getLogs` 호출을 건너뛸 수 있습니다.


---

This is an unofficial plain-language summary. Read the full specification: https://eips.ethereum.org/EIPS/eip-234
