eth_newFilter-Ethereum
The eth_newFilter method creates a filter object based on specified options to notify the client when the state changes, such as new logs. It is part of the Ethereum JSON RPC API
Creates a filter object, based on filter options, to notify when thestate changes (logs)
The eth_newFilter method is part of the Ethereum JSON RPC API and is used to create a filter object based on specified filter options. This method notifies the client when the state changes (logs). To check if the state has changed, the eth_getFilterChanges method can be used.
Supported Networks
The eth_newFilter RPC Ethereum method is supported on the following network types:
Mainnet
Testnet: Sepolia, Holesky
Parameters
The method accepts a filter object with the following keys and their values:
address (optional): A contract address or a list of addresses from which logs should originate.
fromBlock (optional, default is latest): A hexadecimal block number or one of the strings latest, earliest, or pending.
toBlock (optional, default is latest): A hexadecimal block number or one of the strings latest, earliest, or pending.
topics (optional): An array of 32-byte DATA topics. Topics are order-dependent.
Specifying Topic Filters
Topics are order-dependent. A transaction log with topics A, B will match the following topic filters:
[]: Matches anything.
[A]: Matches A in the first position, and anything after.
[null, B]: Matches anything in the first position AND B in the second position, and anything after.
[A, B]: Matches A in the first position AND B in the second position, and anything after.
[[A, B], [A, B]]: Matches (A OR B) in the first position AND (A OR B) in the second position, and anything after.
Request
URL (API Endpoint)
To interact with the Ethereum eth_newFilter endpoint using JSON-RPC, use the following examples:
Response
The response contains the ID of the newly created filter, which can be used to query changes.
Response Description
result: A string containing the filter ID in hexadecimal format. This ID is used with methods such as eth_getFilterChanges or eth_uninstallFilter to manage and query the filter.
Use Case
The eth_newFilter RPC Ethereum method is commonly used in decentralized applications (DApps) and monitoring tools to:
Track specific events or transactions in real time.
Monitor logs emitted by a smart contract.
Create dynamic notifications based on blockchain state changes.
For instance, a Web3 application may call the Ethereumeth_newFilter method to track specific events emitted by a smart contract and update the UI or trigger custom workflows when those events occur.
Code Example
Here is an eth_newFilter example of how to query the method using Python and JavaScript:
Common Errors
When using the eth_newFilter RPC Ethereum method, the following issues may occur:
Invalid URL or ACCESS-TOKEN: Ensure that the URL and token are correct and active.
Incorrect Parameters: Verify that the filter object is formatted correctly.
eth_newFilter error: This error may occur if the node does not support filtering or if the request is malformed.
By integrating the Web3 eth_newFilter method into your application, you can efficiently monitor blockchain logs and events. Use this core API method to create filters and track specific transactions or state changes in real time, enhancing the responsiveness of your DApp or monitoring tools.
Last updated