eth_newFilter - Optimism
Example code for the eth_newFilter json-rpc method. Сomplete guide on how to use eth_newFilter json-rpc in GetBlock.io Web3 documentation.
This method creates a filter that can be polled for new log events matching the specified criteria. The filter can be configured with address, topic, and block-range parameters. Once created, use eth_getFilterChanges to retrieve new logs that match the filter. Filters timeout if not polled regularly.
Parameters
filterObject
Object
Filter object with optional fromBlock, toBlock, address, and topics fields.
Yes
Request sample
Request
curl --location 'https://shared.us-east-1.getblock.io/<ACCESS_TOKEN>' \
--header 'Content-Type: application/json' \
--data '{
"jsonrpc": "2.0",
"method": "eth_newFilter",
"params": [
{
"fromBlock": "latest",
"address": "0x4200000000000000000000000000000000000006",
"topics": [
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"
]
}
],
"id": "getblock.io"
}'import axios from 'axios'
let data = JSON.stringify({
"jsonrpc": "2.0",
"method": "eth_newFilter",
"params": [
{
"fromBlock": "latest",
"address": "0x4200000000000000000000000000000000000006",
"topics": [
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"
]
}
],
"id": "getblock.io"
};
let config = {
method: "post",
maxBodyLength: Infinity,
url: "https://shared.us-east-1.getblock.io/<ACCESS_TOKEN>",
headers: {
"Content-Type": "application/json",
},
data: data,
};
axios
.request(config)
.then((response) => {
console.log(JSON.stringify(response.data));
})
.catch((error) => {
console.log(error);
});
Response
A successful response returns the following:
Response Parameters
id: A unique request identifier, matching theidsent in the request body.jsonrpc: Specifies the use of JSON-RPC version 2.0.result: A filter ID that can be used with eth_getFilterChanges and eth_uninstallFilter.
Use Case
The eth_newFilter method is commonly used for:
Event monitoring
Log polling
Real-time event tracking
Contract event subscription
Error handling
404
Not Found
Missing or invalid ACCESS_TOKEN.
-32602
Invalid argument
Invalid filter parameters
Rate limit
Integration with Web3
Using eth_newFilter allows developers to:
Build interfaces that listen for contract events without needing WebSocket support
Implement background polling workers for analytics dashboards
Detect state changes in dapps and update UI instantly
Create automated bots such as liquidation bots or claim bots
Watch ERC20, ERC721, and custom events in a trustless way
Last updated
Was this helpful?