For testing purpose in test network we are creating account dynamically using ethereum java (EcKey). I have an account that contains enough ethers. How can i transfer ether from the source account to the account newly created using ethereum java. Please suggest.
Asked
Active
Viewed 1,310 times
2 Answers
3
Check any sample from samples source directory how to deal with Transactions, for example, this one: CreateContractSample.java,
Your transaction call should be something like this:
// Amount in ether to send
BigInteger etherToSend = BigInteger.valueOf(100);
// Weis in 1 ether
BigInteger weisInEther = BigInteger.valueOf(1_000_000_000_000_000_000L);
BigInteger weisToSend = weisInEther.multiply(etherToSend);
BigInteger nonce = ethereum.getRepository().getNonce(senderKey.getAddress());
Transaction tx = new Transaction(
ByteUtil.bigIntegerToBytes(nonce),
ByteUtil.longToBytesNoLeadZeroes(ethereum.getGasPrice()),
ByteUtil.longToBytesNoLeadZeroes(3_000_000), // Gas limit
receiveAddress,
ByteUtil.bigIntegerToBytes(weisToSend), // Amount in weis
new byte[0] // We don't need to send any data
);
tx.sign(senderKey);
ethereum.submitTransaction(tx);
Dmitry
- 31
- 1
1
Use the Transaction.java class , create the object with information needed ( the constructor, takes info like from, to address,nonce,gas and value to transfer) and finally sign the transaction and submit.
Abhiram mishra
- 1,922
- 1
- 13
- 23