2

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.

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);
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.

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.