eth_newPendingTransactionFilter
curl --request POST \
--url https://polygon-mainnet.core.chainstack.com/0615fdf3c9eaf0681469e61a4308ea09 \
--header 'Content-Type: application/json' \
--data '
{
"jsonrpc": "2.0",
"method": "eth_newPendingTransactionFilter",
"params": [],
"id": 1
}
'import requests
url = "https://polygon-mainnet.core.chainstack.com/0615fdf3c9eaf0681469e61a4308ea09"
payload = {
"jsonrpc": "2.0",
"method": "eth_newPendingTransactionFilter",
"params": [],
"id": 1
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({jsonrpc: '2.0', method: 'eth_newPendingTransactionFilter', params: [], id: 1})
};
fetch('https://polygon-mainnet.core.chainstack.com/0615fdf3c9eaf0681469e61a4308ea09', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://polygon-mainnet.core.chainstack.com/0615fdf3c9eaf0681469e61a4308ea09",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'jsonrpc' => '2.0',
'method' => 'eth_newPendingTransactionFilter',
'params' => [
],
'id' => 1
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://polygon-mainnet.core.chainstack.com/0615fdf3c9eaf0681469e61a4308ea09"
payload := strings.NewReader("{\n \"jsonrpc\": \"2.0\",\n \"method\": \"eth_newPendingTransactionFilter\",\n \"params\": [],\n \"id\": 1\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://polygon-mainnet.core.chainstack.com/0615fdf3c9eaf0681469e61a4308ea09")
.header("Content-Type", "application/json")
.body("{\n \"jsonrpc\": \"2.0\",\n \"method\": \"eth_newPendingTransactionFilter\",\n \"params\": [],\n \"id\": 1\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://polygon-mainnet.core.chainstack.com/0615fdf3c9eaf0681469e61a4308ea09")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"jsonrpc\": \"2.0\",\n \"method\": \"eth_newPendingTransactionFilter\",\n \"params\": [],\n \"id\": 1\n}"
response = http.request(request)
puts response.read_body{
"jsonrpc": "<string>",
"id": 123,
"result": [
"<string>"
]
}Polygon node API
eth_newPendingTransactionFilter | Polygon
Polygon API method that creates a filter that listens for new pending transactions on the blockchain. Chainstack Polygon reference.
POST
/
0615fdf3c9eaf0681469e61a4308ea09
eth_newPendingTransactionFilter
curl --request POST \
--url https://polygon-mainnet.core.chainstack.com/0615fdf3c9eaf0681469e61a4308ea09 \
--header 'Content-Type: application/json' \
--data '
{
"jsonrpc": "2.0",
"method": "eth_newPendingTransactionFilter",
"params": [],
"id": 1
}
'import requests
url = "https://polygon-mainnet.core.chainstack.com/0615fdf3c9eaf0681469e61a4308ea09"
payload = {
"jsonrpc": "2.0",
"method": "eth_newPendingTransactionFilter",
"params": [],
"id": 1
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({jsonrpc: '2.0', method: 'eth_newPendingTransactionFilter', params: [], id: 1})
};
fetch('https://polygon-mainnet.core.chainstack.com/0615fdf3c9eaf0681469e61a4308ea09', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://polygon-mainnet.core.chainstack.com/0615fdf3c9eaf0681469e61a4308ea09",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'jsonrpc' => '2.0',
'method' => 'eth_newPendingTransactionFilter',
'params' => [
],
'id' => 1
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://polygon-mainnet.core.chainstack.com/0615fdf3c9eaf0681469e61a4308ea09"
payload := strings.NewReader("{\n \"jsonrpc\": \"2.0\",\n \"method\": \"eth_newPendingTransactionFilter\",\n \"params\": [],\n \"id\": 1\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://polygon-mainnet.core.chainstack.com/0615fdf3c9eaf0681469e61a4308ea09")
.header("Content-Type", "application/json")
.body("{\n \"jsonrpc\": \"2.0\",\n \"method\": \"eth_newPendingTransactionFilter\",\n \"params\": [],\n \"id\": 1\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://polygon-mainnet.core.chainstack.com/0615fdf3c9eaf0681469e61a4308ea09")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"jsonrpc\": \"2.0\",\n \"method\": \"eth_newPendingTransactionFilter\",\n \"params\": [],\n \"id\": 1\n}"
response = http.request(request)
puts response.read_body{
"jsonrpc": "<string>",
"id": 123,
"result": [
"<string>"
]
}Polygon 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
Use the following methods with the filter ID:
This code sets up an Ethereum filter to listen for new pending transactions and extract specific data from them.
The code consists of three functions:
eth_getFilterChanges method. The eth_newPendingTransactionFilter method is useful for developers who must be notified of new pending transactions in real time.
Get your own node endpoint todayStart 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).
eth_getFilterChangesto retrieve updateseth_uninstallFilterto remove the filter
eth_newPendingTransactionFilter code examples
Note that the
web3.eth.filter methods have been deprecated and replaced with the web3.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 theeth_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 MATIC token. This could be useful for monitoring high-value transactions or detecting potential fraud or security threats in real time.
Here is an implementation of this concept using ethers.js:
index.js
const ethers = require('ethers');
const NODE_URL = "CHAINSTACK_NODE_URL";
const provider = new ethers.JsonRpcProvider(NODE_URL);
// Create a filter using eth_newPendingTransactionFilter
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);
}
};
// Use the filter to extract the value from each transaction
async function getValue(filter) {
try {
// Retrieve the list of new pending transactions
const transactions = await provider.send('eth_getFilterChanges', [filter]);
// Loop through the list of transactions and process each one
for (const hash of transactions) {
const receipt = await provider.send("eth_getTransactionByHash", [hash]);
// Check that the receipt is not null and has a non-null value field
if (receipt && receipt.value != null) {
const value = receipt.value;
const decimalValue = BigInt(value).toString();
const convertedValue = ethers.utils.formatEther(decimalValue);
// Check if the transferred value is greater than or equal to 100 Matic
if (convertedValue >= 100) {
console.log(`This transaction is sending more than 100 Matic`);
console.log(`Transaction Hash: ${hash}`);
console.log(`Value transferred: ${convertedValue} \n`);
}
}
}
} catch (error) {
console.error(error); // Handle errors that may occur
}
}
// Main program setting an interval to call the `getValue` function at regular intervals
async function main() {
const filterId = await createFilter();
setInterval(getValue, 1000, filterId);
}
main()
createFilter, getValue, and main. Here’s an overview of how each function works:
The createFilter function sets up a new filter using the eth_newPendingTransactionFilter method. It returns the ID of the filter, which can be used to retrieve data from the filter later.
The main function sets up the program by first calling the createFilter function to create a new filter and retrieve its ID. It then sets an interval to call the getValue function every 1 second, passing the filter ID as an argument to retrieve the latest transaction data at regular intervals.Last modified on July 24, 2026
Was this page helpful?