Querying Ethereum Logs With eth_getLogs vs a SQL Indexer
Bottom line: Pulling a month of ERC-20 Transfer events from a hosted RPC endpoint with eth_getLogs is possible but brittle — block-range caps, response size limits, and per-request billing make it a poor fit for anything past ad-hoc lookups. A local Postgres indexer turns the same query into a millisecond SQL scan and is the only sane way to do it repeatedly.
Not investment advice. This describes how the mechanism works and what the operational risks are. It does not tell you what to buy. See the editorial policy.
The task was simple on paper: get every ERC-20 Transfer event for a specific token over a 30-day window, then answer questions about holder concentration and transfer velocity. I tried the obvious path first — point a script at a hosted RPC provider and call eth_getLogs with a block range covering the month. Then I built a small Postgres indexer and ran the same query against it. This is what I found, with the numbers and the failure modes.
How eth_getLogs actually behaves
eth_getLogs takes a filter object with fromBlock, toBlock, address, and topics. It returns an array of log objects — address, topics, data, blockNumber, transactionHash, logIndex, and so on. It is a stateless JSON-RPC call, so there is no cursor, no pagination, and no server-side state between requests. You ask for a range, you get everything in it or you get an error.
The filter is the only lever you have. For ERC-20 Transfers the topic filter is the keccak hash of Transfer(address,address,uint256), which is 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef. The from and to addresses sit in topics[1] and topics[2] as 32-byte left-padded values; the amount is in data. A minimal curl call looks like this:
1 | curl -s https://eth-mainnet.example.com/v2/$API_KEY \ |
That works fine for a few thousand blocks. The problem is the word “month.” At roughly 7,200 blocks per day on mainnet, 30 days is around 216,000 blocks. No hosted provider will serve that in one call.
The block-range limit is the first wall
Provider documentation is explicit about this. On the free tier, most chains cap a single eth_getLogs query at 10 blocks. Pay-as-you-go tiers typically allow up to 10,000 blocks per call, with a note that wider ranges are “less likely to succeed.” Responses are also capped at 150MB regardless of plan. Enterprise tiers lift the block cap but not the response cap.
So a 216,000-block month becomes, at best, 22 sequential calls at 10,000 blocks each — and each of those calls must succeed. In practice I found that even 10,000-block windows over a busy token like USDC regularly blew past the 150MB response cap, forcing me to halve the window again. The effective chunk size ended up being closer to 2,000–4,000 blocks for high-volume tokens.
| Constraint | Free tier | Pay-as-you-go | Enterprise | Effect on a 30-day query |
|---|---|---|---|---|
| Max blocks per call | 10 | 10,000 | 10,000+ | 216,000 blocks → 22+ calls minimum |
| Response size cap | 150MB | 150MB | 150MB | Forces smaller chunks on busy tokens |
| Compute units per call | 60 | 60 | 60 | Billed per call, not per block |
| Practical chunk size (USDC) | ~10 | ~2,000–4,000 | ~2,000–4,000 | 50–100 calls for one month |
The compute-unit figure matters more than it looks. A eth_getLogs call costs 60 CUs regardless of how many blocks or logs it returns. Splitting a query into 100 smaller calls costs 100× the CUs of one call, even though the total data returned is identical. This is the structural reason RPC indexing gets expensive fast.
Where the timeout bites
The second wall is time. Hosted providers enforce per-request timeouts — typically 10–30 seconds depending on tier. A 10,000-block query over a token with heavy transfer volume can take long enough to hit that ceiling, especially when the provider is under load. When it does, you get a JSON-RPC error object with a message like query timeout exceeded or an HTTP 504, and the entire chunk is lost. You have to retry with a smaller range.
I wrote a retry loop that halves the block range on timeout and backs off exponentially. It works, but it means the actual number of calls is unpredictable — a nominal 22-call job turned into 60+ calls on a bad afternoon. That unpredictability is fine for a one-off script and unacceptable for anything on a schedule.
1 | # Chunked pull with halving-on-timeout, writing NDJSON |
Building the Postgres indexer
The indexer is not complicated. It uses ethereum-etl (or the Rust rewrite, ethereum-etl.rs, which the project claims is about 1.4× faster with the same CLI) to stream blocks, logs, and decoded token transfers into Postgres. The schema is a handful of tables: blocks, transactions, logs, and a token_transfers table with token_address, from_address, to_address, value, block_number, and log_index.
1 | pip3 install ethereum-etl[streaming] |
Once the data is in, the query that took 60+ RPC calls becomes a single indexed scan:
1 | SELECT from_address, to_address, value, block_number |
With a composite index on (token_address, block_number), this returns in tens of milliseconds on a laptop-class machine. The same query against the RPC path took minutes of wall-clock time and dozens of billed calls. The indexer’s backfill for a 30-day window took a few hours on a single core and cost nothing beyond the RPC calls to fetch blocks — and those calls are eth_getBlockByNumber and eth_getLogs at one block per request, which is far cheaper per unit of data than the chunked approach.
Querying chain data directly: when it still makes sense
An indexer is not always the right answer. For a one-off investigation — “did this address ever receive this token” — a single eth_getLogs with a tight block range is faster than standing up a database. For monitoring a single contract’s events in real time, a websocket subscription to logs is better than polling. The indexer wins when you need to query the same data repeatedly, join it against other tables, or run aggregations.
The rule I settled on: if the query runs more than a handful of times, or spans more than a few thousand blocks, index it. If it is a one-shot lookup over a narrow range, hit the RPC.
Pitfalls and how to diagnose them
- Silent truncation at 150MB. The provider returns a valid response, but it is incomplete. You will not get an error. Diagnose by comparing
result.lengthagainst the expected log count from a block explorer, or by checking whether the last returnedblockNumbermatches yourtoBlock. If it does not, the response was truncated. - Timeout errors that look like network errors. A 504 from a proxy in front of the provider is not the same as a JSON-RPC error. Parse the response body, not just the status code. If the body is not valid JSON-RPC, treat it as a timeout and halve the range.
- Reorg-induced gaps. A chunked pull that spans several minutes can straddle a reorg. Logs from orphaned blocks will appear in your dataset and then vanish from the canonical chain. Diagnose by storing
blockHashalongsideblockNumberand re-checking a sample againsteth_getBlockByNumberwithfinalizedas the block tag. - Topic padding mistakes. Addresses in
topicsmust be 32-byte left-padded. Passing a 20-byte address returns zero results with no error. Diagnose by logging the exact filter object sent and comparing against a known-good query. - CU billing surprises. The bill is per call, not per block. A job that splits into 100 calls costs 100× a single call. Diagnose by logging every request and summing CUs before you scale up.
- Indexer drift. A streaming indexer that falls behind the head will silently serve stale data. Diagnose by tracking the latest
block_numberin the table against the chain head and alerting on lag.
FAQ
Why does eth_getLogs cap block ranges at all?
Because the node has to scan every block in the range and decode every matching log, and a wide range over a busy contract can exhaust memory or exceed the request timeout. The caps are a load-shedding mechanism, not an arbitrary restriction.
Can I get around the block-range limit by using a different provider?
Some providers offer wider ranges on higher tiers, but the 150MB response cap applies across the board. For high-volume tokens the response cap, not the block cap, becomes the binding constraint.
Is a local indexer cheaper than paying for RPC calls?
For repeated queries, yes — dramatically. The indexer pays once for the backfill and then serves queries for free. The RPC path pays per call, every time, and the per-call cost is fixed regardless of how little data you actually need.
How do I handle chain reorganizations in an indexer?
Track blockHash for every row, and on startup re-verify the last N blocks against the canonical chain using the finalized block tag. Roll back any rows whose blockHash no longer matches. A depth of 64 blocks covers most reorgs on mainnet.
Do I need a full archive node to run an indexer?
No. You only need blocks from your start point forward, so a full node synced from genesis or a provider that serves historical blocks works. Archive nodes are only necessary if you need historical state, not historical logs.
What about tax and accounting implications of the data I pull?
The on-chain data is just data — the tax treatment depends on your jurisdiction and what the transfers represent. Consult a qualified accountant; nothing in the query mechanics changes the reporting obligation.









