eth_getLogs - Somnia

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

This method returns an array of all logs matching a given filter object on the Somnia network. This is essential for tracking events emitted by smart contracts, monitoring DeFi activities, and building event-driven applications.

Parameters

Parameter
Type
Required
Description

filterObject

object

Yes

The filter options

Filter Object

Field
Type
Required
Description

fromBlock

string

No

Starting block (hex or "latest", "earliest")

toBlock

string

No

Ending block (hex or "latest", "earliest")

address

string/array

No

Contract address(es) to filter

topics

array

No

Array of topic filters

blockHash

string

No

Restrict to single block by hash

Request Example

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

Response Example

Response Parameters

Parameter
Type
Description

address

string

Contract that emitted the log

topics

array

Indexed event parameters

data

string

Non-indexed event data

blockNumber

string

Block containing the log

transactionHash

string

Transaction that created the log

logIndex

string

Log position in block

removed

boolean

True if log was removed due to reorg

Use Cases

  • Track ERC-20 token transfers

  • Monitor NFT mints and transfers

  • Index DeFi protocol events

  • Build event-driven applications

  • Create analytics dashboards

Error Handling

Error Code
Description

-32602

Invalid params - malformed filter

-32603

Internal error - node processing issues

-32005

Query returned too many results

SDK Integration

Last updated

Was this helpful?