通过Web3.py在Infura节点上获取以太坊txpool待处理事务的不同方法

问题描述 投票:3回答:1

我想通过Web3.py在以太坊txpool中看到实时的未决交易。我没有运行本地节点,而是使用Infura。

根据Web3.py的文档,很明显,其中一个具有三个不同的选项:

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

选项1不可行,因为API似乎不支持Infura节点。因此,我尝试了选项2和3,它们给了我两组不同的待处理交易。有谁知道为什么会这样吗?两种方法是否检索不同的未决事务?谢谢!

选项2

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

选项3

pending_transactions_filter= w3.eth.filter('pending')
pending_transactions= pending_transactions_filter.get_new_entries()
python ethereum web3
1个回答
0
投票

这些是根本上不同的事务集,因为似乎选项2仅在未决块上进行过滤,但选项3甚至包含了甚至不在待决块中的更多未决事务。这对我来说很明显,因为选项2允许您获取完整的tx内容/信息,但是选项3仅给了我txhash ID,其中许多无法查找。

© www.soinside.com 2019 - 2024. All rights reserved.