簡體   English   中英

如何使用Web3在以太坊中獲得未決交易?

[英]How to get pending transactions in ethereum using web3?

我需要在以太web3中使用web3計算連續交易的現時數,但getTransactionCount不會返回未決交易。

有沒有一種方法可以使用web3獲取所有交易,包括未決交易和已完成交易? 如果不是web3 ,還有其他方法嗎?

這是一個已知的問題# 1741 ,也許您可​​以更好地等待交易被清除。

您嘗試使用web3.eth.filter嗎?

下面的代碼應該工作。 (目前無法測試自己)

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

web3.eth.filter(options, (error, result) => {
  if (!error)
    console.log(result);
});

使用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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM