2

I tried to send a signedTransaction using a low gas price (it's my will to test timeoute of my scripts)

I supposed also that a not mined transaction was 'pending', so I tried checking, while the first transaction has not been mined yet, using

web3.eth.getPendingTransactions();

I got every time an empty array.

Why?

So, what is a pending transaction?

2 Answers 2

1

This function returns all pending transactions in a node's mempool, but it doesn't work in Web3.js.

To read a node's mempool using Web3.js, you need to add a custom call -

//add txpool support
web3.extend({
   property: 'txpool',
   methods: [{
      name: 'content',
      call: 'txpool_content'
   }]
})

Then call it -

web3.txpool.content((err, data) => {
   console.log(err, data)
});

If you want to check a specific transaction status, you can use web3.eth.getTransactionReceipt(txHash), if you get null, that transaction wasn't mined yet (still pending).

1

web3.eth.getPendingTransactions(); returns an empty array because it's supposed to only return the transactions originating from an account on the node itself (not all pending transactions). Check source.

Good explanation here too.

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.