The eth_newPendingTransactionFilter method creates a filter in the node to notify when new pending transactions arrive.
Creates a filter in the node, to notify when new pending transactionsarrive. To check if the state has changed, call eth_getFilterChanges.
The eth_newPendingTransactionFilter method is part of the Ethereum JSON-RPC API and is used to create a filter in the node to notify when new pending transactions arrive. This method is essential for monitoring transaction activity in real time. To check for updates, the eth_getFilterChanges method can be called.
The eth_newPendingTransactionFilter RPC Ethereum method works across various Ethereum network types, including:
Mainnet
Testnet: Sepolia, Holesky
URL (API Endpoint)
https://go.getblock.io/<ACCESS-TOKEN>/
To interact with the Ethereum eth_newPendingTransactionFilter endpoints using JSON-RPC, use the following examples
curl --location --request POST 'https://go.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
"jsonrpc": "2.0",
"method": "eth_newPendingTransactionFilter",
"params": [],
"id": "getblock.io"
}'
wscat -c wss://go.getblock.io/<ACCESS-TOKEN>/
# wait for connection and send the request body
{"jsonrpc": "2.0",
"method": "eth_newPendingTransactionFilter",
"params": [],
"id": "getblock.io"}
The response contains the ID of the newly created filter, which can be used to query changes.
{
"id": "getblock.io",
"jsonrpc": "2.0",
"result": "0x55c90c9069cac4e02c8868aa6e437dbb"
}
result: A string containing the filter ID in hexadecimal format. This value can be used with methods such as eth_getFilterChanges or eth_uninstallFilter to manage and query the filter.
The eth_newPendingTransactionFilter RPC Ethereum method is widely used in decentralized applications (DApps) and monitoring tools to:
Track pending transactions in real time.
Monitor network activity for transaction patterns or anomalies.
Provide dynamic notifications to users about transactions in progress.
For instance, a Web3 application may use the Ethereum eth_newPendingTransactionFilter method to notify users about their pending transactions and update the application state based on transaction status.
Here is an eth_newPendingTransactionFilter example of how to query the method using Python and JavaScript:
import requests
import json
# Define the API URL and headers
url = 'https://go.getblock.io/<ACCESS-TOKEN>/'
headers = {'Content-Type': 'application/json'}
# Prepare the request data
data = {
"jsonrpc": "2.0",
"method": "eth_newPendingTransactionFilter",
"params": [],
"id": "getblock.io"
}
# Send the POST request
response = requests.post(url, headers=headers, data=json.dumps(data))
# Parse the JSON response
response_data = response.json()
# Print the result
print(json.dumps(response_data, indent=4))
const axios = require('axios');
// Define the API URL and headers
const url = 'https://go.getblock.io/<ACCESS-TOKEN>/';
const headers = { 'Content-Type': 'application/json' };
// Prepare the request data
const data = {
jsonrpc: '2.0',
method: 'eth_newPendingTransactionFilter',
params: [],
id: 'getblock.io'
};
// Send the POST request
axios.post(url, data, { headers })
.then(response => {
// Print the result
console.log('Filter ID:', response.data.result);
})
.catch(error => {
console.error('Error:', error);
});
When using the eth_newPendingTransactionFilter RPC Ethereum method, the following issues may occur:
Invalid URL or ACCESS-TOKEN: Ensure the URL and token are correct and active.
Network Connectivity Problems: Verify that the network being queried is reachable and the correct endpoint is being used.
eth_newPendingTransactionFilter error: This error may occur if the node does not support filtering or if the request is malformed.
By integrating the Web3 eth_newPendingTransactionFilter method into your application, you can efficiently track transaction activity. Use this core API method to monitor pending transactions and provide a responsive user experience in real time.