My application is dealing with high speed RPC requests, so it cannot reply on synchronous blocking call to process requests. It wants web3j RPC calls to return tx hash immediately without blocking and invoke callback later after RPC completion. Can web3j do callback as follows as in web3js?

web3.eth.sendTransaction({data: code}, function(err, transactionHash) {
  if (!err)
    console.log(transactionHash); // "0x7f9fade1c0d57a7af66ab4ead7c2eb7b11a91385"

You can use Promise. First create a promise object then execute task inside the promise. The following code will solve the problem.

var TxPromsie = new Promise(function(resolve, reject) {  
                var tx = web3.eth.sendTransaction({data: code});  
                if (tx != null) {  
                } else {  
                   reject('could not get transaction data');  
            TxPromsie.then(function(value) {  
            }).catch(function(error) {  

This might help you!

  • Unfortunately, I'm using web3j Java, not javascript. Any idea how to do similarly in web3j Java? – sinoTrinity Apr 24 '18 at 13:24
  • @sinoTrinity I have no idea on webj. – Gopal ojha Apr 24 '18 at 15:05

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.