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(
"mypassword",
"path\\to\\keystore");
EthGetTransactionCount ethGetTransactionCount = web3.ethGetTransactionCount(
from, DefaultBlockParameterName.LATEST).sendAsync().get();
BigInteger nonce = ethGetTransactionCount.getTransactionCount();
System.out.println(nonce);
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