BNB Smart Chain
eth_getLogs
BNB Smart Chain is the EVM-compatible network secured by Proof-of-Staked-Authority, where validators are paid in BNB and roughly three-second blocks reach fast finality. eth_getLogs walks the historical chain and returns every event log that matches a single filter object in one round trip. That object pins down addresses, indexed topics, and a block window. Point your client at https://bsc.therpc.io/YOUR_API_KEY on chain ID 56, and this becomes the workhorse for one-shot log pulls and backfill indexing jobs, sweeping past PancakeSwap swaps or BEP-20 Transfer events without holding an open subscription.
Use cases
- Backfill every
Transferlog emitted by a BEP-20 token contract across a historical range of chain-56 blocks. - Feed a DeFi analytics dashboard by harvesting Venus borrow/repay or PancakeSwap pair events into a database.
- Rebuild a contract's current state from scratch by replaying its past emitted events in block order.
- Confirm that one expected event actually fired inside a given BSC transaction during integration testing.
Parameters
| # | Name | Type | Required | Description |
|---|---|---|---|---|
| 1 | filter | object | Yes | Filter object. Fields: `fromBlock` (string, default "latest"), `toBlock` (string, default "latest"), `address` (string | string[]), `topics` ((string | string[] | null)[]), `blockHash` (string — mutually exclusive with fromBlock/toBlock). |
Response
| Type | Description |
|---|---|
| array | Array of log objects. Each log: `address`, `blockHash`, `blockNumber`, `data`, `logIndex`, `removed` (bool — true on reorg), `topics`, `transactionHash`, `transactionIndex`. |
Example request
Try it live in the BNB Smart Chain playground.
Errors & troubleshooting
| Code | Message | Cause |
|---|---|---|
-32005 | query exceeds max block range | The fromBlock–toBlock window exceeds the provider's block-range cap. |
-32005 | query returned more than 10000 results | Too many matching logs; narrow the filter or paginate. |
-32602 | invalid argument | blockHash combined with fromBlock/toBlock, or malformed topic format. |
Common pitfalls
- Although PoSA gives BNB Smart Chain quick finality, logs from not-yet-final blocks can still vanish on a short reorg. Inspect each entry's
removedflag and re-pull once the block settles. - Skip the address and topic filters or span too wide a window, and you hit range-cap errors plus sluggish responses. Slice the work into windows of about 1,000 to 5,000 blocks.
- Hammering this method in a tight loop with
fromBlock: "latest"burns compute units for nothing. Wire upeth_newFilterpluseth_getFilterChanges, or open aneth_subscribestream instead.
Supported networks
- Mainnet — Chain ID: 56
- Testnet — Chain ID: 97
See also
Parameters
Filter object. Fields: `fromBlock` (string, default "latest"), `toBlock` (string, default "latest"), `address` (string | string[]), `topics` ((string | string[] | null)[]), `blockHash` (string — mutually exclusive with fromBlock/toBlock).