I built a java web application which connects using Web3j with my smart contract deployed on Ropsten Network.

My web application provides a control panel to allow the user to send transactions to the smart contract. Sometimes the user can send more than 5 calls at the same time. (actually much more than 5 :) )

I have a java class wrapper of my smart contract to call the functions of it.

The question is: What I have to use, send() or sendAsync? How to manage() I tried to use send() and sendAync().get() and I got the same result.

TransactionReceipt receipt = myContract.callFunction1(...)         

What I get with this code is a long wait to complete the call and get the transaction receipt.... Is there another way to do this?

I know this could involve promises but I am not familiar with them. Could someone provide some code?

Thanks in advance


You can send and confirm transaction without waiting using CompletableFuture and callback function. rc-> Instance that calls contract function through remote call.

CompletableFuture<TransactionReceipt> transactionReceiptCompletableFuture = rc.sendAsync();

transactionReceiptCompletableFuture.thenAccept(transactionReceipt -> {

   // then accept gets transaction receipt only if the transaction is successful

 }).exceptionally(transactionReceipt  -> {
    return null;
  • While implementing this and start debugging, it always jumps over the thenAccept and my IDE is telling me that CompletableFuture is not completed which ends in an Exception. Maybe I misunderstood the concept. Can someone give some further explanation with maybe some deeper/more code snippets? – Tobias Apr 29 at 7:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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