BNB Smart Chain

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 Transfer log 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

#NameTypeRequiredDescription
1filterobjectYesFilter 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

TypeDescription
arrayArray of log objects. Each log: `address`, `blockHash`, `blockNumber`, `data`, `logIndex`, `removed` (bool — true on reorg), `topics`, `transactionHash`, `transactionIndex`.

Example request

curl https://bsc.therpc.io/YOUR_API_KEY \
-X POST \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "eth_getLogs",
"params": [{}],
"id": 1
}'

Try it live in the BNB Smart Chain playground.

Errors & troubleshooting

CodeMessageCause
-32005query exceeds max block rangeThe fromBlock–toBlock window exceeds the provider's block-range cap.
-32005query returned more than 10000 resultsToo many matching logs; narrow the filter or paginate.
-32602invalid argumentblockHash 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 removed flag 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 up eth_newFilter plus eth_getFilterChanges, or open an eth_subscribe stream 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).

curl https://bsc.therpc.io/YOUR_API_KEY \
-X POST \
-H 'Content-Type: application/json' \
-d '{"jsonrpc":"2.0","id":1,"method":"eth_getLogs","params":[{}]}'

Ready to call this in production?

Free tier covers personal projects. Pay-as-you-go scales without a card.