0

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 we try after sometime, they get proper response.

So wanted to ask if we can have any other method where we can listen all new incoming transactions and getTransaction for them?

2

when transaction is just submitted into network, its still pending, you need to wait for it to be mined then only the web3.eth.getTransaction return correct value, put in in the loop with settimeout.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.