(Pending) transaction with hash: 0xxxx... Not found?

Hi,

I’m subsribing to ‘newPendingTransactions’ and I’m getting a bunch of them, so that’s fine. The problem comes when I try to get the info of each transaction using w3.eth.getTransaction(tx). Some of them work fine and return the info, while others (many, about half of them) throw the Exception:
web3.exceptions.TransactionNotFound: Transaction with hash: 0x74335b11… not found

If I look for those transactions in etherscan.io, it shows that they indeed exist and are pending. What is going on here? Why can’t I fetch the data of these transactions?

This is my function:

msg = {"id": 1, "method": "eth_subscribe", "params": ["newPendingTransactions"]}
async def pending_tx():
    async with websockets.connect(API) as ws:
        await ws.send(json.dumps(msg))
        while ws.open:
            response = json.loads(await ws.recv())
            try:
                print(w3.eth.getTransaction(response['params']['result']))
            except Exception as e:
                print(tb.print_exc())

Another question I have regarding the subscription to pending tx: Does it indeed show every pending transaction sent to the miners? If not, what type of transactions is not showing, or why wouldn’t it show certain tx?

Thanks!

Hi @leon.berrosa, and welcome to the Infura community!
It looks like you’re calling w3.eth.getTransaction fairly immediately after you get those new pending transactions. When a tx hash is published to the subscriber, it’s not guaranteed to be processed for serving on the API. The solution to this is to retry after a short interval of time. If you put in a slight pause before running the getTransaction call, you should see less of this error.

1 Like

You are right Leiya, thanks a lot!

1 Like