web3.eth.getTransaction(txHash) returns null

I am using web3.eth.subscribe for logs and then, I am passing transaction hash of that event to web3.eth.getTransaction function. But, it returns null.

I am using the main ethereum network.

Plase, help.

1 Like

Could you provide us with your code generating this request and the response you are receiving?

var subscription = web3.eth.subscribe('logs', {
        address: '0x123456..',
        topics: ['0x12345...']
    }, function(error, result){
        if (error){
            console.log(error);
        }
            
        web3.eth.getTransaction(result.transactionHash).then(function(res) {
            console.log(res);
        });
    });

In this code, res returns null.

Are you able to confirm that the subscription is returning a successful result? Can you include where res is being defined?

Yes, the subscription is returning the correct result. I did check by printing result in the console. res is a variable and it should ideally print the result. I did check the same function locally and it works fine. It works with private ethereum network too.

Hi @princesinha. This could either be because of a blockchain reorg event or because of the delayed data propagation between our event subscription infrastructure and other parts of our system. We are working to minimize this propagation delay but in the near term, we recommend that you retry getting the transaction by hash several times with an exponential backoff before returning an error. the null response indicates that the node you are querying does not have the requested transaction hash.

Thanks, @egalano.

Yes for any other method call inside subscribe event, It returns null.

Oh man this helped me a lot thank you!