1 min read - Posted 18 Dec 19

Sending an Ether Transfer Transaction from One Account to Another in Web3j

To transfer ether from one account to another, a transaction must be sent to the ethereum network. The easiest way to achieve this within your java application is to use the useful Transfer class of web3j.

The below example transfers 1 ether from the seed phrase account to the recipientAddress account:

//Connect to node
//Defaults to http://localhost:8545
Web3j web3 = HttpService());  // defaults to http://localhost:8545/

//Generate wallet credentials from a mnemonic seed phrase
Credentials credentials = WalletUtils.loadBip39Credentials("password", "mnemonic");

//The address that the ether should be transferred to
String recipientAddress = "0xF0f15Cedc719B5A55470877B0710d5c7816916b1";

//The ether amount to transfer.
BigDecimal amountInEther = BigDecimal.valueOf(1.0);

//Send the transfer transaction.
//Unit conversion is handled automatically and this method blocks until the transaction has been mined.
TransactionReceipt transactionReceipt = Transfer.sendFunds(
        web3, credentials, recipientAddress,
        amountInEther, Convert.Unit.ETHER).send();

Note that there are multiple ways to generate wallet credentials. For more imformation, check out Managing an Ethereum Account with Java and Web3j.

Created with Sketch.Content is"CC-BY-SA 4.0" licensed
Article On-chain
Article Author

Craig Williams

Software Developer @ Kauri / ConsenSys




Related Articles
Signing an Ethereum Transaction in Web3j

Web3j provides a bunch of helper classes to enable you to create and sign a transaction within your ethereum java code. The transaction creation process involve

Web3j Transaction Managers

A Transaction Manager in Web3j is an abstraction that controls how transactions are signed and broadcast to the Ethereum network, via a connected client. You can pass an implementation to a smart contract wrapper when deploying or loading a contract, or you can use it to directly send transactions in a more manual way. There are multiple different Transaction Manager implementations included, all extending the TransactionManager abstract class. Each extending class must implement the abstract se