I am working on custom blockchain testnet.
I wanna see all pending transactions on my local block explorer.
To do this I first tried with web3.eth.getPendingTransactions()
but it always returned empty array even though there is a pending transaction.
So I tried with web3.eth.subscribe
with pendingTransaction
parameter.
const Web3 = require("web3");
const web3 = new Web3("ws://192.168.112.82:7001");
var pndTxns = [];
web3.eth
.subscribe("pendingTransactions", function (error, result) {
if (!error) console.log(result);
})
.on("data", function (transaction) {
pndTxns.push(transaction);
console.log(pndTxns);
}
console.log(pndTxns);
It actually worked in web3.eth.subscription
block, but outside of that pndTxns
logs empty array.
I tried to find answer for several days but not found yet.
So how can I get all pending transactions at the moment at once?
Any help will be really appreciated.