Transfer U2U

Summary

In this section, you will learn how to transfer HBAR from your account to another on the Hedera test network.

Prerequisites

Note: You can always check the "Code Check ✅ " section at the bottom of each page to view the entire code if you run into issues. You can also post your issue to the respective SDK channel in our Discord community here or on the GitHub repository here.

Step 1. Create a transfer transaction

Use your new account created in the "Create an account" section and transfer 1,000 tinybars from your account to the new account. The account sending the HBAR needs to sign the transaction using its private keys to authorize the transfer. Since you are transferring from the account associated with the client, you do not need to explicitly sign the transaction as the operator account(account transferring the HBAR) signs all transactions to authorize the payment of the transaction fee.

//System.out.println("The new account balance is: " +accountBalance.hbars);
//-----------------------<enter code below>--------------------------------------

//Transfer HBAR
TransactionResponse sendHbar = new TransferTransaction()
     .addHbarTransfer(myAccountId, Hbar.fromTinybars(-1000)) //Sending account
     .addHbarTransfer(newAccountId, Hbar.fromTinybars(1000)) //Receiving account
     .execute(client);

Note: The net value of the transfer must equal zero (the total number of HBAR sent by the sender must equal the total number of HBAR received by the recipient).

Step 2. Verify the transfer transaction reached consensus

To verify the transfer transaction reached consensus by the network, you will submit a request to obtain the receipt of the transaction. The receipt status will let you know if the transaction was successful (reached consensus) or not.

Code Check ✅

Your complete code file should look something like this:

Java
JavaScript
Go

Sample output:

Have a question? Ask it on StackOverflow

Last updated