Hedera
Search…
Transfer cryptocurrency
A transaction that transfers hbars and tokens between Hedera accounts. You can enter multiple transfers in a single transaction. The net value of hbars between the sending accounts and receiving accounts must equal zero.
    The maximum allowable balance adjustment in a single transfer transaction is 20. A debit from one account and credit to another account equals two balance adjustments.
    If you are transferring a token with custom fees, only two levels of nesting of fees are allowed
    The sending account is responsible to pay for the custom token fees
Transaction Signing Requirements
    The account sending the tokens is required to sign the transaction.
Constructor
Description
new TransferTransaction()
Initializes the TransferTransaction object
1
new TransferTransaction()
Copied!
V2
V1

Methods

Method
Type
Description
addHbarTransfer(<accountId, value>)
AccountID, Hbar
The account the transfer is being debited from. The sending account must sign the transaction. The sender and recipient values must net zero.
addTokenTransfer(<tokenId, accountId,value>)
TokenId, AccountId, long
The ID of the token, the account ID to transfer the tokens from, and the value of the token to transfer. The sender and recipient values must net zero.
Java
1
// Create a transaction to transfer 100 hbars
2
TransferTransaction transaction = new TransferTransaction()
3
.addHbarTransfer(OPERATOR_ID, new Hbar(-10))
4
.addHbarTransfer(newAccountId, new Hbar(10));
5
6
//Submit the transaction to a Hedera network
7
TransactionResponse txResponse = transaction.execute(client);
8
9
//Request the receipt of the transaction
10
TransactionReceipt receipt = txResponse.getReceipt(client);
11
12
//Get the transaction consensus status
13
Status transactionStatus = receipt.status;
14
15
System.out.println("The transaction consensus status is " +transactionStatus);
16
17
//Version 2.0.0
Copied!
JavaScript
1
// Create a transaction to transfer 100 hbars
2
const transaction = new TransferTransaction()
3
.addHbarTransfer(OPERATOR_ID, new Hbar(-100))
4
.addHbarTransfer(newAccountId, new Hbar(100));
5
6
//Submit the transaction to a Hedera network
7
const txResponse = await transaction.execute(client);
8
9
//Request the receipt of the transaction
10
const receipt = await txResponse.getReceipt(client);
11
12
//Get the transaction consensus status
13
const transactionStatus = receipt.status;
14
15
console.log("The transaction consensus status is " +transactionStatus.toString());
16
17
//v2.0.5
Copied!
Go
1
// Create a transaction to transfer 100 hbars
2
transaction := hedera.NewTransferTransaction().
3
AddHbarTransfer(client.GetOperatorAccountID(), hedera.NewHbar(-1)).
4
AddHbarTransfer(hedera.AccountID{Account: 3}, hedera.NewHbar(1))
5
6
//Submit the transaction to a Hedera network
7
txResponse, err := transaction.Execute(client)
8
9
if err != nil {
10
panic(err)
11
}
12
13
//Request the receipt of the transaction
14
receipt, err := txResponse.GetReceipt(client)
15
16
if err != nil {
17
panic(err)
18
}
19
20
//Get the transaction consensus status
21
transactionStatus := receipt.Status
22
23
fmt.Printf("The transaction consensus status is %v\n", transactionReceipt.Status)
24
25
//Version 2.0.0
Copied!
Method
Type
Description
addHbarTransfer(<accountId, value>)
AccountId, Hbar/long
The account the transfer is being debited from. The sending account must sign the transaction. The sender and recipient values must net zero.
addTokenTransfer(<tokenId, accountId,value>)
TokenId, AccountId, long
The ID of the token, the account ID to transfer the tokens from, value of the token to transfer. The sender and recipient values must net zero.
Java
1
//Create the transfer transaction
2
TransferTransaction transaction = new TransferTransaction()
3
.addHbarTransfer(OPERATOR_ID, new Hbar(-10))
4
.addHbarTransfer(newAccountId, new Hbar(10));
5
6
//Sign with the client operator key and submit the transaction to a Hedera network
7
TransactionId txId = transaction.execute(client);
8
9
//Request the receipt of the transaction
10
TransactionReceipt receipt = txId.getReceipt(client);
11
12
//Get the transaction consensus status
13
Status transactionStatus = receipt.status;
14
15
System.out.println("The transaction consensus status is " +transactionStatus);
16
17
//v1.3.2
Copied!
JavaScript
1
//Create the transfer transaction
2
const transaction = new TransferTransaction()
3
.addHbarTransfer(OPERATOR_ID, new Hbar(-10))
4
.addHbarTransfer(newAccountId, new Hbar(10));
5
6
//Sign with the client operator key and submit the transaction to a Hedera network
7
const txId = await transaction.execute(client);
8
9
//Request the receipt of the transaction
10
const receipt = await txId.getReceipt(client);
11
12
//Get the transaction consensus status
13
const transactionStatus = receipt.status;
14
15
console.log("The transaction consensus status is " +transactionStatus);
16
17
//v1.4.4
Copied!

Get transaction values

V2
Method
Type
Description
getHbarTransfers()
Map<AccountId, Hbar>
Returns a list of the hbar transfers in this transaction
getTokenTransfers()
Map<TokenId, Map<AccountId, long>>
Returns the list of token transfers in the transaction
Java
1
// Create a transaction
2
CryptoTransferTransaction transaction = new CryptoTransferTransaction()
3
.addSender(OPERATOR_ID, new Hbar(10))
4
.addRecipient(newAccountId, new Hbar(10));
5
6
//Get transfers
7
List<Transfer> transfers = transaction.getTransfers();
8
9
//v2.0.0
Copied!
JavaScript
1
// Create a transaction
2
const transaction = new CryptoTransferTransaction()
3
.addSender(OPERATOR_ID, new Hbar(10))
4
.addRecipient(newAccountId, new Hbar(10));
5
6
//Get transfers
7
const transfers = transaction.getTransfers();
8
9
//v2.0.0
Copied!
Go
1
// Create a transaction
2
transaction := hedera.NewTransferTransaction().
3
AddHbarTransfer(client.GetOperatorAccountID(), hedera.NewHbar(-1)).
4
AddHbarTransfer(hedera.AccountID{Account: 3}, hedera.NewHbar(1))
5
//Get transfers
6
transfers := transaction.GetTransfers()
7
8
//v2.0.0
Copied!
Last modified 6d ago
Copy link