githubEdit

eth_getLogs - Base

Example code for the eth_getLogs JSON-RPC method. Complete guide on how to use eth_getLogs JSON-RPC in GetBlock Web3 documentation.

The eth_getLogs method returns an array of all logs matching a given filter object. This is the primary method for querying event logs from smart contracts, essential for tracking token transfers, DEX swaps, and other on-chain events.

Parameters

Parameter
Type
Required
Description

filterObject

object

Yes

Filter options object

Filter Object

Field
Type
Required
Description

fromBlock

string

No

Start block number (hex) or "latest", "earliest"

toBlock

string

No

End block number (hex) or "latest", "earliest"

address

string/array

No

Contract address or array of addresses

topics

array

No

Array of topic filters (up to 4 topics)

blockHash

string

No

Specific block hash (alternative to fromBlock/toBlock)

Request

curl --location --request POST 'https://go.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
    "jsonrpc": "2.0",
    "method": "eth_getLogs",
    "params": [{
        "fromBlock": "0x12d6800",
        "toBlock": "0x12d6900",
        "address": "0x4200000000000000000000000000000000000006",
        "topics": ["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"]
    }],
    "id": "getblock.io"
}'

Response

Response Parameters

Parameter
Type
Description

address

string

Contract address that emitted the log

topics

array

Indexed event parameters (up to 4)

data

string

Non-indexed event data (hex)

blockNumber

string

Block number in hex

transactionHash

string

Transaction hash

transactionIndex

string

Transaction index in block (hex)

blockHash

string

Block hash

logIndex

string

Log index in block (hex)

removed

boolean

True if log was removed due to chain reorg

Use Cases

  • Token Transfer Tracking: Monitor ERC-20/ERC-721 transfers

  • DEX Event Processing: Track swaps, liquidity events

  • Contract Event Indexing: Build event-driven databases

  • Real-time Notifications: Alert on specific events

  • Historical Analysis: Analyze past contract activity

Error Handling

Error Code
Message
Description

-32602

Invalid params

Invalid filter object

-32603

Internal error

Query range too large or node failure

-32005

Query returned more than limit

Too many logs in response

Web3 Integration

Last updated

Was this helpful?