0

I have been working on my project where I use web3j. I work with ledger over contract wrappers where the actual call to the ledger is encapsulated over variety of layers.

The issue is I need to get a hash of tx when it has been put into the pool, not after it has been mined.

Current implementation of the contract wrappers gives me txReceipt only after it has been mined. I have not found yet any way to get it before it has been mined.

Do you know a solution?

A wider context is after the call to the chain from a mobile client, I need to verify does tx succeed or not. I plan to do it via call web3.ethGetTransactionByHash(txHash).

1 Answer 1

1

You can subscribe to PendingTransactionFlowable API of the Web3J to get txHash as soon as it is submitted to mempool. But thing to note here is that this transaction MAY BE rejected due to any error..... So make sure you write another logic where you compare the transactionHash when it has received at least 1 confirmation.

web3j.pendingTransactionFlowable().subscribe(x-> {
     log.info(x.getHash());
});
1
  • 1
    Thank you, it is good to know about this approach. docs.web3j.io/4.9.8/getting_started/pub_sub/#filters However, it could not be used in my case. Web3J is used on mobile side and keeping network connection permanently open will drain mobile battery pretty soon. Also I tried filter ledger events for another task and that case shown a bad performance results. I did a workaround about my issue by splitting concerns of submit tx on chain and listen for confirmation in two separate tasks. Here is more info: gelassen.github.io/blog/2023/04/15/swap-tech-notes-part-3.html.
    – Gleichmut
    Commented May 2, 2023 at 14:10

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.