eth_newPendingTransactionFilter - Bitlayer
This method creates a filter that reports the hashes of new pending transactions entering the mempool, and returns a filter ID.
Parameters
This method does not require any parameters. Send the request with an empty params array.
Request
bashcurl --location --request POST 'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
"jsonrpc": "2.0",
"method": "eth_newPendingTransactionFilter",
"params": [],
"id": "getblock.io"
}'example.js
javascriptconst axios = require('axios');
const response = await axios.post('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/', {
jsonrpc: '2.0',
method: 'eth_newPendingTransactionFilter',
params: [],
id: 'getblock.io'
}, {
headers: { 'Content-Type': 'application/json' }
});
console.log(response.data.result);example.py
pythonimport requests
response = requests.post(
'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/',
headers={'Content-Type': 'application/json'},
json={
'jsonrpc': '2.0',
'method': 'eth_newPendingTransactionFilter',
'params': [],
'id': 'getblock.io'
}
)
print(response.json())example.rs
rustuse reqwest::Client;
use serde_json::{json, Value};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = Client::new();
let response = client
.post("https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/")
.header("Content-Type", "application/json")
.json(&json!({
"jsonrpc": "2.0",
"method": "eth_newPendingTransactionFilter",
"params": [],
"id": "getblock.io"
}))
.send()
.await?
.json::<Value>()
.await?;
println!("Result: {}", response["result"]);
Ok(())
}Response
json{
"jsonrpc": "2.0",
"id": "getblock.io",
"result": "0x4d1b6f9a2c7e3805b1d4a6f8e0c2b3a5"
}Response Parameters
| Parameter | Type | Description |
|---|---|---|
| jsonrpc | string | JSON-RPC protocol version ("2.0") |
| id | string | Request identifier matching the request |
| result | string | Hex-encoded filter ID |
Use Cases
- Mempool Watching: Observe incoming pending transactions
- Nonce Tracking: Detect a pending transaction from a watched address
- Latency Analysis: Measure time from mempool entry to inclusion
- Polling Pipelines: Create a filter, then poll for new pending hashes
Error Handling
| Error Code | Message | Description |
|---|---|---|
| -32603 | Internal error | The node failed to register the pending filter |
| -32601 | Method not found | Filters are disabled on the client build |
Web3 Integration
ethers-example.js
javascriptimport { ethers } from 'ethers';
const provider = new ethers.JsonRpcProvider('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/');
provider.on('pending', (txHash) => console.log(txHash));viem-example.js
javascriptimport { createPublicClient, http } from 'viem';
const client = createPublicClient({
transport: http('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/')
});
const unwatch = client.watchPendingTransactions({ onTransactions: (h) => console.log(h) });