Nethereum – How to Get the List of Pending Transactions

nethereum

Currently I'm using GetBlockWithTransactionsByNumber by looping into the latest 200 blocks to get the transactions sent to my address. I can actually get my transaction through the block number but what about the pending transaction which has no block number yet (haven't mined to a block).

enter image description here

Best Answer

The txpool_content inspection property can be queried to list the exact details of all the transactions currently pending for inclusion in the next block(s), as well as the ones that are being scheduled for future execution only.

Refernce : https://github.com/ethereum/go-ethereum/wiki/Management-APIs#txpool

This API is not directly available.So you can integrate the txpool_content API using the following code.

                  web3.currentProvider.sendAsync({
                         method: "txpool_content",
                         params: [],
                         jsonrpc: "2.0",
                         id: new Date().getTime()
                  }, function(error, result) {
                       console.log(result);
                       if (result.result.pending) {
                            if (result.result.pending[address]) {   //address -external input
                                var txnsCount = 
                               Object.keys(result.result.pending[consumerAddress]).length;
                                 console.log("txnsCount: "+txnsCount);
                            }
                         }
              })
Related Topic