BNB API method that creates a filter that listens for new pending transactions on the blockchain. It returns a filter ID, which can be used to retrieve the results using the eth_getFilterChanges method. The eth_newBlockFilter
method is useful for developers who must be notified of new blocks on the blockchain in real-time.
Get you own node endpoint today
Start for free and get your app to production levels immediately. No credit card required.
You can sign up with your GitHub, X, Google, or Microsoft account.
Parameters
none
Response
result
— a hexadecimal string representing the ID of the newly created filter
Code examples
The filters created are stored on the blockchain client instance. The filter is automatically deleted if not polled within a certain time (5 minutes by default).
Use the following methods with the filter ID:
- eth_getFilterChanges to retrieve updates
- eth_uninstallFilter to remove the filter
eth_newPendingTransactionFilter
code examples
eth_newPendingTransactionFilter
code examplesNote that the
web3.eth.filter
methods have been deprecated and replaced with theweb3.eth.subscribe
in web3.js. See web3.js subscriptions.
const ethers = require('ethers');
const NODE_URL = "CHAINSTACK_NODE_URL";
const provider = new ethers.JsonRpcProvider(NODE_URL);
const createFilter = async () => {
try {
const filterId = await provider.send('eth_newPendingTransactionFilter', []);
console.log(filterId); // the filter ID returned by eth_newFilter
return filterId
} catch (error) {
console.log(error);
}
};
createFilter();
from web3 import Web3
node_url = "CHAINSTACK_NODE_URL"
web3 = Web3(Web3.HTTPProvider(node_url))
def get_new_pending_transactions():
try:
blocks_filter = web3.eth.filter('pending')
# Split the string at the space character
parts = str(blocks_filter).split(' ')
# Extract the filter value from the second part
filter_id = parts[2]
return filter_id
except Exception as e:
print(e)
new_filter = get_new_pending_transactions()
print(new_filter)
Use case
One way to use the eth_newPendingTransactionFilter
method is to listen for new pending transactions at predefined intervals and extract specific data from them. For instance, a decentralized application might check for pending transactions every second and identify those that transfer a value greater than a certain amount of the ETH token. This could be useful for real-time monitoring high-value transactions or detecting potential fraud or security threats.
Try the eth_newPendingTransactionFilter
RPC method yourself
eth_newPendingTransactionFilter
RPC method yourself