I have subscribed to ETH pendingTransactions in mainnet. I am doing getTransaction for each received pendingTransaction like below.
web3.eth.subscribe('pendingTransactions', function(error, txnid) {
if (txnid) {
web3.eth.getTransaction(txnid, function(err, txn) {
if (!err) {
console.log(txn);
}
else
console.log(err);
});
}
else
console.log(error);
});
My issue is, I am getting txn=null for some of the txnid. And if I try after some time, I get proper response.
Is there any other method to listen all new incoming transactions and getTransaction
for them?