如何使用 web3 获取以太坊中待处理的交易?

Abh*_*wat 6 blockchain ethereum web3js

我需要在以太坊中使用 web3js 计算连续交易的随机数,但getTransactionCount不返回待处理的交易。

有没有办法使用 web3js 获取所有交易,包括待处理和已完成的交易?如果不是web3js,还有其他方法吗?

Atu*_*Atu 1

您尝试过使用web3.eth.filter吗?

以下代码应该可以工作。(暂时无法测试自己)

var options = {
  fromBlock: "pending",
  toBlock: "latest",
  address: "0xabc123...",
}

web3.eth.filter(options, (error, result) => {
  if (!error)
    console.log(result);
});
Run Code Online (Sandbox Code Playgroud)

  • @AbhishekKumawat 我的朋友,你提到的 [doc](https://web3js.readthedocs.io/en/1.0/web3-eth.html) 是针对 web3.js **v1.0** 我的那个我们提到的是 [**web3 0.xx**](https://github.com/ethereum/wiki/wiki/JavaScript-API#web3ethfilter) (2认同)