I'm trying to transfer ETH from one account to another using web3j and a java program using following code.

public void transfer (String from, String to, BigInteger amount) throws InterruptedException, ExecutionException, IOException, CipherException{
     Credentials credentials1 = WalletUtils.loadCredentials(

     EthGetTransactionCount ethGetTransactionCount = web3.ethGetTransactionCount(
             from, DefaultBlockParameterName.LATEST).sendAsync().get();

     BigInteger nonce = ethGetTransactionCount.getTransactionCount();

     RawTransaction rawTransaction = RawTransaction.createEtherTransaction (
             nonce, Convert.toWei("22", Convert.Unit.MWEI).toBigInteger(), Convert.toWei("44", Convert.Unit.GWEI).toBigInteger(), to, amount);
     byte[] signedMessage = TransactionEncoder.signMessage(rawTransaction, credentials1);
     String hexValue = Numeric.toHexString(signedMessage);

     EthSendTransaction ethSendTransaction = web3.ethSendRawTransaction(hexValue).sendAsync().get();
     String transactionHash = ethSendTransaction.getTransactionHash();

But I cannot get it to work. Also the nonce doesn't change and keeps returning 44.

I am running it on the Ropsten test net.

Any thoughts?

Thanks, Coen


With some help from the creator of web3 I was able to solve this.


static final BigInteger GAS_PRICE = BigInteger.valueOf(20_000_000_000L);
static final BigInteger GAS_LIMIT = BigInteger.valueOf(4_300_000);


RawTransaction rawTransaction = RawTransaction.createEtherTransaction (
             nonce, GAS_PRICE, GAS_LIMIT, to, amount);

I managed to transfer the ether.

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.