2

Im trying to send 0 ether to the same account with Web3j, however when i run this code it give me directly the transaction hash, even if the transaction has not been mined yet and still pending. I can't use the method Transfer.sendFund(..) because i need the nonce to be given by me.

RawTransaction rawTransaction = RawTransaction.createEtherTransaction(nonce, 
    gasPriceInWei, gasLimit, credentials.getAddress(), BigInteger.ZERO);

byte[] signedMessage = TransactionEncoder.signMessage(rawTransaction, 
    credentials);

String hexValue = Numeric.toHexString(signedMessage);

EthSendTransaction ethSendTransaction =
    web3j.ethSendRawTransaction(hexValue).sendAsync().get();

String transactionHash = ethSendTransaction.getTransactionHash();

System.out.println("transaction hash: " , transactionHash )

Does anyone have an idea to solve this probelm?

("web3j.ethSendRawTransaction(hexValue).send()" dont solve this)

(watch all new transactions in each new blocks until my transaction occure is a solution, but is there a better way)?

2

That worked for me:

while (true) {
    EthGetTransactionReceipt transactionReceipt = web3j
        .ethGetTransactionReceipt(transactionHash)
        .send();
     if (transactionReceipt.getResult() != null) {
         break;
     }
     Thread.sleep(15000);
}

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.