eth_getLogs - Sonic
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 event logs that match a filter over a range of blocks. It is the primary method for reading historical events such as ERC-20 transfers and contract events.
Parameters
filter
object
Yes
Filter object selecting the logs to return
Filter Object
fromBlock
string
No
Start block in hex, or "latest", "earliest"
toBlock
string
No
End block in hex, or "latest", "earliest"
address
string or array
No
Contract address or addresses to filter by
topics
array
No
Event signature and indexed topics to match
blockHash
string
No
Restrict to a single block by hash, instead of a range
Request
curl --location --request POST 'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
"jsonrpc": "2.0",
"method": "eth_getLogs",
"params": [{"fromBlock": "0x1e8400", "toBlock": "0x1e8480", "address": "0x039e2fB66102314Ce7b64Ce5Ce3E5183bc94aD38", "topics": ["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"]}],
"id": "getblock.io"
}'const axios = require('axios');
const response = await axios.post('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/', {
jsonrpc: '2.0',
method: 'eth_getLogs',
params: [{"fromBlock": "0x1e8400", "toBlock": "0x1e8480", "address": "0x039e2fB66102314Ce7b64Ce5Ce3E5183bc94aD38", "topics": ["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"]}],
id: 'getblock.io'
}, {
headers: { 'Content-Type': 'application/json' }
});
console.log(response.data.result);import requests
response = requests.post(
'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/',
headers={'Content-Type': 'application/json'},
json={
'jsonrpc': '2.0',
'method': 'eth_getLogs',
'params': [{"fromBlock": "0x1e8400", "toBlock": "0x1e8480", "address": "0x039e2fB66102314Ce7b64Ce5Ce3E5183bc94aD38", "topics": ["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"]}],
'id': 'getblock.io'
}
)
print(response.json())Response
Response Parameters
jsonrpc
string
JSON-RPC protocol version ("2.0")
id
string
Request identifier matching the request
result
array
Array of log objects matching the filter
Log Object
address
string
Contract that emitted the log
topics
array
Indexed event topics, starting with the event signature
data
string
Non-indexed event data, hex-encoded
blockNumber
string
Block the log was emitted in
transactionHash
string
Transaction that emitted the log
removed
boolean
Whether the log was removed by a reorganization
Use Cases
Transfer Tracking: Read ERC-20 Transfer events for an address or token
Event Indexing: Ingest contract events into an off-chain database
DeFi Monitoring: Watch swap, mint, and burn events on pools
Notifications: Trigger alerts on specific contract events
Analytics: Aggregate historical event data over block ranges
Error Handling
-32602
Invalid params
The filter object is malformed or the block range is invalid
-32005
Limit exceeded
The requested block range or result set is too large
-32603
Internal error
The node failed to read the logs
Web3 Integration
Last updated
Was this helpful?