2

I used the following code to send a transaction and get transaction status.However, sometimes the transaction is not minded at all. But the transactionReceipt get the same value "NULL" for both of the "not mined" and pending status.

Is there a way to get different values for these 2 status so we can resubmit the transaction when the status is not mined??

EthSendTransaction ethSendTransaction = web3j.ethSendRawTransaction(hexValue).sendAsync().get()
EthGetTransactionReceipt transactionReceipt = web3j.ethGetTransactionReceipt(transactionHash).sendAsync().get();

2 Answers 2

2

In Web3 v1.2.6:

To get the pending transactions, use the below API:

const pendingTransactions = await web3.eth.getPendingTransactions()

To check the whether your transactionHash is in the pendingTransactions array:

Let transactionHash be the one you want to check whether it is pending or mined.

const isMyTxPending = pendingTransactions.filter((tx) => if (tx === transactionHash) {
  return true;
} else {
  return false;
})

Then isMyTxPending equals to true implies your transaction is not yet mined and it is in pending state else it is mined.

1

Referring to web3.eth.getTransaction, You could check on its return for blockNumber value. If the blockNumber value is null means the transaction is still pending.

More info here: http://web3js.readthedocs.io/en/1.0/web3-eth.html#gettransaction

1
  • I know how to get the pending transaction.But how to check if the transaction is being mined or not? Sometimes, the transaction is not even being mined and the blocknumber value is also null.
    – vaj oja
    Commented Jul 8, 2018 at 6:46

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.