Subscribe pendingTransactions retrieves confirmed tx's and no pending tx

I use the following code to subscribe to the infura wss to retrieve pendingTransactions in real time. However I don’t receive realtime pending transactions anymore. Every new txHash that I receive belongs to a transaction that is on average 40 seconds to a minute old and is already confirmed in 1+ blocks.

this.subscription = this.web3ws.eth.subscribe(pendingTransactions, (err, res) => {
if (err) console.error(err);}

this.subscription.on(‘data’, (txHash) => { setTimeout(async () => {
try {
let tx = await this.web3.eth.getTransaction(txHash);

I tried the same method a few days ago and managed to get real time pending transactions however since 2 days this does not work anymore. The code is 100 % identical to what I used a few days ago. Is it possible that the infura websocket is lagging behind, or perhaps the subscribe function is not synced or something?

Hi @sdfg_jajaja - welcome to the Infura community!

I would suggest using eth_subscribe with the newPendingTransactions parameter. You can get more detailed information from our docs here. This should help fix your problem and ensure you’re getting consistent results.

1 Like