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 Fees
  • Please see the transaction and query fees table for base transaction fee
  • Please use the Hedera fee estimator to estimate your transaction fee cost
Spender Account Allowances
Available on previewnet and testnet as part of the 0.25 release.
An account can have another account spend tokens on its behalf. If the delegated spender account is transacting tokens from the owner account that authorized the allowance, the owner account needs to be specified in the transfer transaction by calling one of the following:
  • addApprovedHbarTransfer()
  • addApprovedTokenTransfer()
  • addApprovedNftTransfer()
  • addApprovedTokenTransferWithDecimals()
The debiting account is the owner account when using this feature.
Transaction Signing Requirements
  • The accounts the tokens are being debited from are required to sign the transaction
    • If an authorized spender account is spending on behalf of the account that owns the tokens then the spending account is required to sign
  • The transaction fee paying account is required to sign the transaction
Constructor
Description
new TransferTransaction()
Initializes the TransferTransaction object
1
new TransferTransaction()
Copied!

Methods

V2
V1

​

Method
Type
Description
addHbarTransfer(<accountId>, <value>)
​AccountId, Hbar
The account involved in the transfer and the number of hbars. The sender and recipient values must net zero.
addTokenTransfer(<tokenId>, <accountId>,<value>)
​TokenId, AccountId, long
The ID of the token, the account ID involved in the transfer, and the number of tokens to transfer. The sender and recipient values must net zero.
addNftTransfer(<nftId>, <sender>, <receiver>)
​NftId, AcountId, AccountId​
The NFT ID (token + serial number), the sending account, and receiving account.
addTokenTransferWithDecimals(<tokenId>, <accountId>, <value>, <int>)
​TokenId, AccountId, long, decimals
The ID of the token, the account ID involved in the transfer, the number of tokens to transfer, the decimals of the token. The sender and recipient values must net zero.
addApprovedHbarTransfer(<ownerAccountId>,<amount>)
​AccountId, Hbar
The owner account ID the spender is authorized to transfer from and the amount. Applicable to allowance transfers only.
addApprovedTokenTransfer(<tokenId>, <accountId>, <value>)
​TokenId, AccountId, long
The owner account ID and token the spender is authorized to transfer from. The debiting account is the owner account. Applicable to allowance transfers only.
addApprovedTokenTransferWithDecimals(<tokenId>, <accountId>, <value>, <decimals>)
​TokenId, AccountId, long, int
The owner account ID and token ID (with decimals) the spender is authorized to transfer from. The debit account is the account ID of the sender. Applicable to allowance transfers only.
addApprovedNftTransfer(<nftId>,<sender>, <receiver>)
​NftId, AcountId, AccountId​
The NFT ID the spender is authorized to transfer. The sender is the owner account and receiver is the receiving account. Applicable to allowance transfers only.
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!