eth_newFilter - GIWA
Example code for the eth_newFilter JSON-RPC method. Complete guide on how to use eth_newFilter JSON-RPC in GetBlock Web3 documentation.
This method creates a log filter matching address and topic criteria and returns a filter ID. New matching logs are then retrieved with eth_getFilterChanges.
Parameters
filterObject
object
Yes
Filter criteria object
Filter Object
fromBlock
string
No
Start block in hex, or "latest"
toBlock
string
No
End block in hex, or "latest"
address
string
array
No
topics
array
No
Ordered topic filters (null matches any)
Request
curl --location --request POST 'https://shared.ap-southeast-1.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
"jsonrpc": "2.0",
"method": "eth_newFilter",
"params": [{ "fromBlock": "0x14b8a10", "toBlock": "latest", "address": "0x4200000000000000000000000000000000000006", "topics": ["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"] }],
"id": "getblock.io"
}'const axios = require('axios');
const response = await axios.post('https://shared.ap-southeast-1.getblock.io/<ACCESS-TOKEN>/', {
jsonrpc: '2.0',
method: 'eth_newFilter',
params: [{ fromBlock: '0x14b8a10', toBlock: 'latest', address: '0x4200000000000000000000000000000000000006', topics: ['0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'] }],
id: 'getblock.io'
}, {
headers: { 'Content-Type': 'application/json' }
});
console.log(response.data.result);import requests
response = requests.post(
'https://shared.ap-southeast-1.getblock.io/<ACCESS-TOKEN>/',
headers={'Content-Type': 'application/json'},
json={
'jsonrpc': '2.0',
'method': 'eth_newFilter',
'params': [{ 'fromBlock': '0x14b8a10', 'toBlock': 'latest', 'address': '0x4200000000000000000000000000000000000006', '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
string
Hex-encoded filter ID
Use Cases
Event Watching: Track ERC-20 Transfer events for a token contract
Polling Pipelines: Create a filter, then poll changes on an interval
Topic Filtering: Match specific event signatures by topic0
Multi-Contract Watch: Watch several addresses with one filter
Error Handling
-32602
Invalid params
Malformed filter object or topic list
-32603
Internal error
The node failed to register the filter
Web3 Integration
Last updated
Was this helpful?