[英]How to get pending transactions in ethereum using web3?
I need to calculate the nonce for successive transactions using web3
in Ethereum, but getTransactionCount
does not return pending transactions. 我需要在以太
web3
中使用web3
计算连续交易的现时数,但getTransactionCount
不会返回未决交易。
Is there a way to get all transactions including both pending and completed transactions using web3
?? 有没有一种方法可以使用
web3
获取所有交易,包括未决交易和已完成交易? If not web3
, is there some other way to do that?? 如果不是
web3
,还有其他方法吗?
这是一个已知的问题# 1741 ,也许您可以更好地等待交易被清除。
Did you try using web3.eth.filter ? 您尝试使用web3.eth.filter吗?
Following code should work. 下面的代码应该工作。 (unable to test myself at the moment)
(目前无法测试自己)
var options = {
fromBlock: "pending",
toBlock: "latest",
address: "0xabc123...",
}
web3.eth.filter(options, (error, result) => {
if (!error)
console.log(result);
});
using web3js 1.0 you can use getPendingTransactions
使用web3js 1.0可以使用
getPendingTransactions
web3.eth.getPendingTransactions().then(console.log);
> [
{
hash: '0x9fc76417374aa880d4449a1f7f31ec597f00b1f6f3dd2d66f4c9c6c445836d8b',
nonce: 2,
blockHash: '0xef95f2f1ed3ca60b048b4bf67cde2195961e0bba6f70bcbea9a2c4e133e34b46',
blockNumber: 3,
transactionIndex: 0,
from: '0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b',
to: '0x6295ee1b4f6dd65047762f924ecd367c17eabf8f',
value: '123450000000000000',
gas: 314159,
gasPrice: '2000000000000',
input: '0x57cb2fc4'
v: '0x3d',
r: '0xaabc9ddafffb2ae0bac4107697547d22d9383667d9e97f5409dd6881ce08f13f',
s: '0x69e43116be8f842dcd4a0b2f760043737a59534430b762317db21d9ac8c5034'
},....,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.