0

I'm trying to get information whether there are pending transactions for the given address. My code is as follows:

web3.eth.getTransactionCount(‘ADDRESS’, ‘pending’, function(error, result){
  if(!error)
      console.log(JSON.stringify(result));
  else
      console.error(error);
})

This works, however it returns the count of ALL of the transactions I see in Metamask, not just the ones in "pending" state.

Any clues how can I get only the pending ones?

Thanks!

1
  • only at Etherscan. Otherwise , setup an ethereum node, and query against the txpool. Also fyi, the count of all the transactions of an account is called nonce
    – Nulik
    Commented Aug 31, 2018 at 22:00

1 Answer 1

0

pending is a special state in ethereum, containing transactions that will likely be in the next block. If you make a transaction with a very low gas price, you will not end up in the pending state.

Since pending is a defined state, when you query the pending tx count, you are querying the expected tx count after one more block has been mined, which will naturally contain the count of transactions before it.

If you wish to just list unmined transactions, your best bet is to retrieve the txpool, and parse that for your address.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.