[Ethereum] How to get a pending transaction? I am using python with web3py

etherscanpending-transactionspythonweb3.py

I am using the URL "https://mainnet.infura.io/v3/key".
But I can't get a pending transaction.
This is my code.

pendingTransaction = web3.eth.filter('pending')

I had an error like this.

The method eth_newPendingTransactionFilter does not exist/is not available.

What reason this error?

Best Answer

You cannot get pending transactions using the standard Infura endpoint. I recommend to use chainstack.com, it's free and it works.

Then you can use web3.py to get the pending transactions. I have a repo about this here if you want to check it out. But the main code is this:

# retrive pending transactions hash
pending_tx_filter = web3.eth.filter('pending')
pending_tx = pending_tx_filter.get_new_entries()     

# loop through the list of transcations and displays the tx hash
for hash in pending_tx:
    print('Hash of a Pending Transaction:' , web3.toHex(hash))