A transaction that transfers HBAR and tokens between Hedera accounts. You can enter multiple transfers in a single transaction. The net value of HBAR between the sending accounts and receiving accounts must equal zero.
For a CryptoTransferTransactionBody:
Max of 10 balance adjustments in its HBAR transfer list.
Max of 10 fungible token balance adjustments across all its token transfer list.
Max of 10 NFT ownership changes across all its token transfer list.
Max of 20 balance adjustments or NFT ownership changes implied by a transaction (including custom fees).
If you are transferring a token with custom fees, only two levels of nesting 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 the base transaction fee
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's account when using this feature.
Note: The allowance spender must pay the fee for the transaction.
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
Methods
// Create a transaction to transfer 1 HBAR TransferTransaction transaction =newTransferTransaction().addHbarTransfer(OPERATOR_ID,newHbar(-1)).addHbarTransfer(newAccountId, evmAddress,newHbar(1));//Submit the transaction to a Hedera networkTransactionResponse txResponse =transaction.execute(client);//Request the receipt of the transactionTransactionReceipt receipt =txResponse.getReceipt(client);//Get the transaction consensus statusStatus transactionStatus =receipt.status;System.out.println("The transaction consensus status is "+transactionStatus);//Version 2.0.0
// Create a transaction to transfer 1 HBARconsttransaction=newTransferTransaction().addHbarTransfer(OPERATOR_ID,newHbar(-1)).addHbarTransfer(newAccountId, evmAddress,newHbar(1));//Submit the transaction to a Hedera networkconsttxResponse=awaittransaction.execute(client);//Request the receipt of the transactionconstreceipt=awaittxResponse.getReceipt(client);//Get the transaction consensus statusconsttransactionStatus=receipt.status;console.log("The transaction consensus status is "+transactionStatus.toString());//v2.0.0
// Create a transaction to transfer 1 HBARtransaction :=hedera.NewTransferTransaction().AddHbarTransfer(client.GetOperatorAccountID(),hedera.NewHbar(-1)).AddHbarTransfer(hedera.AccountID{Account:3},hedera.NewHbar(1))//Submit the transaction to a Hedera networktxResponse, err :=transaction.Execute(client)if err != nil {panic(err)}//Request the receipt of the transactionreceipt, err :=txResponse.GetReceipt(client)if err != nil {panic(err)}//Get the transaction consensus statustransactionStatus :=receipt.Statusfmt.Printf("The transaction consensus status is %v\n",transactionReceipt.Status)//Version 2.0.0
Get transaction values
// Create a transaction CryptoTransferTransaction transaction =newCryptoTransferTransaction().addSender(OPERATOR_ID,newHbar(1).addRecipient(newAccountId,newHbar(1));//Get transfersList<Transfer> transfers =transaction.getTransfers();//v2.0.0
// Create a transaction consttransaction=newCryptoTransferTransaction().addSender(OPERATOR_ID,newHbar(1)).addRecipient(newAccountId,newHbar(1));//Get transfersconsttransfers=transaction.getTransfers();//v2.0.0
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.
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.
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.
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.
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