eth_getLogs
Returns an array of all logs matching a given filter object on the Unichain network. Essential for querying historical events and monitoring smart contract activity.
Parameters​
filter
(object, required): The filter object with the following optional properties:fromBlock
(string, optional): Block number or tag ("earliest", "latest", "pending", "safe", "finalized") to start searching fromtoBlock
(string, optional): Block number or tag to stop searching ataddress
(string or array, optional): Contract address or array of addresses to filter logs fromtopics
(array, optional): Array of 32-byte DATA topics. Topics are order-dependent:- First topic is usually the event signature hash
- Use
null
to match any value at a specific position - Can provide arrays for "OR" conditions at each position
blockHash
(string, optional): Restricts logs to a specific block (incompatible with fromBlock/toBlock)
Returns​
An array of log objects, each containing:
address
(string): Address from which this log originatedtopics
(array of strings): Array of 0 to 4 32-byte DATA topicsdata
(string): Contains non-indexed arguments of the logblockNumber
(string): Block number where this log was includedblockHash
(string): Hash of the block where this log was includedtransactionHash
(string): Hash of the transaction that created this logtransactionIndex
(string): Transaction index position in the blocklogIndex
(string): Integer of the log index position in the blockremoved
(boolean): true when the log was removed due to a chain reorganization
Implementation Example​
- cURL
- JavaScript
- Python
curl -X POST https://api-unichain-mainnet.n.dwellir.com/YOUR_API_KEY \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "eth_getLogs",
"params": [{
"fromBlock": "0x1",
"toBlock": "latest",
"address": "0x1234567890abcdef1234567890abcdef12345678",
"topics": [
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"
]
}],
"id": 1
}'
const response = await fetch('https://api-unichain-mainnet.n.dwellir.com/YOUR_API_KEY', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
jsonrpc: '2.0',
method: 'eth_getLogs',
params: [{
fromBlock: '0x1',
toBlock: 'latest',
address: '0x1234567890abcdef1234567890abcdef12345678',
topics: [
'0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'
]
}],
id: 1
})
});
const data = await response.json();
console.log(data.result);
import requests
import json
url = 'https://api-unichain-mainnet.n.dwellir.com/YOUR_API_KEY'
headers = {'Content-Type': 'application/json'}
payload = {
"jsonrpc": "2.0",
"method": "eth_getLogs",
"params": [{
"fromBlock": "0x1",
"toBlock": "latest",
"address": "0x1234567890abcdef1234567890abcdef12345678",
"topics": [
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"
]
}],
"id": 1
}
response = requests.post(url, headers=headers, data=json.dumps(payload))
data = response.json()
print(data['result'])
Response Example​
{
"jsonrpc": "2.0",
"id": 1,
"result": [
{
"address": "0x1234567890abcdef1234567890abcdef12345678",
"topics": [
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
"0x0000000000000000000000009876543210fedcba9876543210fedcba98765432",
"0x000000000000000000000000fedcba0987654321fedcba0987654321fedcba09"
],
"data": "0x0000000000000000000000000000000000000000000000000de0b6b3a7640000",
"blockNumber": "0x1b4",
"blockHash": "0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890",
"transactionHash": "0xfedcba0987654321fedcba0987654321fedcba0987654321fedcba0987654321",
"transactionIndex": "0x1",
"logIndex": "0x0",
"removed": false
}
]
}
Advanced Usage​
Filter by Multiple Addresses​
{
"address": [
"0x1234567890abcdef1234567890abcdef12345678",
"0xabcdef1234567890abcdef1234567890abcdef12"
]
}
Complex Topic Filtering​
{
"topics": [
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
null, // Any value for second topic
[ // OR condition for third topic
"0x0000000000000000000000001234567890abcdef1234567890abcdef12345678",
"0x000000000000000000000000abcdef1234567890abcdef1234567890abcdef12"
]
]
}
Notes​
- Block Range Limits: Free plans typically limited to 5 blocks, paid plans up to 10,000 blocks
- Topics are Order-Dependent: The first topic is usually the event signature hash
- Use null for Wildcards: In the topics array, use
null
to match any value at that position - Performance: Large block ranges or broad filters may result in slower responses
- Block Tags: Supports "earliest", "latest", "pending", "safe", and "finalized"
Need help? Contact our support team or check the Unichain documentation.