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

1

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()
Watcher answered 25/7, 2019 at 12:23 Comment(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)Huth
It has been quiet some time, since this post was created, but is someone here able to answer my question (#70234659) to the Value error that occurs, when I am trying out option 3?Junto
Option 3 does not work for infura nodes, does it?Unnamed
E
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.

Extended answered 18/5, 2020 at 23:18 Comment(1)
what about 1st question (txpool) ?Heterotopia

© 2022 - 2024 — McMap. All rights reserved.