Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different ways of getting Ethereum txpool pending transactions at Infura node via Web3.py

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? Thanks!

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()
like image 956
yisenhower Avatar asked Jul 25 '19 12:07

yisenhower


1 Answers

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.

like image 107
Camandre Avatar answered Sep 28 '22 08:09

Camandre