8

I would like to see the real-time pending transactions in the Ethereum txpool via Web3.py. I do not run a local node but use Infura instead.

According to the documentation of Web3.py, apparently one has three different options:

  1. Use TX Pool API
  2. Use web3.eth.getBlock('pending')
  3. Use web3.eth.filter('pending')

Option 1 is not viable as the API does not seem to support Infura node. Thus I tried option 2 & 3 and they give me two different sets of pending transactions. Does anyone know why it is the case? Do the two methods retrieve different pending transactions?

Option 2:

pending_block= w3.eth.getBlock(block_identifier='pending', full_transactions=True)
pending_transactions= pending_block.['transactions']

Option 3:

pending_transactions_filter= w3.eth.filter('pending')
pending_transactions= pending_transactions_filter.get_new_entries()
TylerH
  • 20,799
  • 66
  • 75
  • 101
yisenhower
  • 81
  • 1
  • 3
  • That's right, you'll se different pending txs each time you set up the listener, because it only shows txs added after you start listening to it. It doesn't return all txs in the pool (unfortunately) – AFMeirelles Oct 23 '19 at 13:08
  • It has been quiet some time, since this post was created, but is someone here able to answer my question (https://stackoverflow.com/questions/70234159/web3-py-valueerror-when-using-pending-filter) to the Value error that occurs, when I am trying out option 3? – nilsmelchert Dec 05 '21 at 12:18
  • Option 3 does not work for infura nodes, does it? – Lorry Jun 06 '22 at 02:28

1 Answers1

4

These are different transaction sets fundamentally as it seems Option 2 just filters on a pending block, but Option 3 includes even more pending transactions that are not even in a pending block. This is evident to me because Option 2 allows you to get full tx content/info, but Option 3 only gives me the txhash IDs, many of which cannot be looked up.

Camandre
  • 51
  • 4