Skip to main content
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
  • Please use the Hedera fee estimator to estimate your transaction fee cost
Spender Account Allowances 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.
Account Allowance Hooks (HIP-1195) An account can have Hiero Hooks that act as programmable allowances. Instead of using traditional ERC-style allowances, a TransferTransaction can reference a hook on the sending or receiving account. The hook’s EVM bytecode runs and must return true for the transfer to proceed. This enables custom validation logic like one-time passcodes, compliance rules, or conditional transfer approvals. To invoke a hook, use the WithHook variants of the transfer methods:
  • addHbarTransferWithHook() — HBAR transfers with a FungibleHookCall
  • addTokenTransferWithHook() — Fungible token transfers with a FungibleHookCall
  • addNftTransferWithHook() — NFT transfers with optional sender and receiver NftHookCall
The counterpart transfer entry (the other side of the zero-sum) is added separately with the standard addHbarTransfer(), addTokenTransfer(), or addNftTransfer() methods.
Hook Invocation LimitsChild records generated by hook calls are capped at 50 per transaction (consensus.handle.maxFollowingRecords=50). Hook executions are not supported in batch or scheduled transactions.
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

MethodTypeDescription
addHbarTransfer(<accountId>, <evmAddress>, <value>)AccountId, string, HBARThe account involved in the transfer and the number of HBAR. The sender and recipient values must net zero.
addTokenTransfer(<tokenId>, <accountId>, <evmAddress>, <value>)TokenId, AccountId, string, longThe 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, AccountId, AccountIdThe NFT ID (token + serial number), the sending account, and receiving account.
addTokenTransferWithDecimals(<tokenId>, <accountId>, <value>, <int>)TokenId, AccountId, long, decimalsThe 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, HbarThe owner account ID the spender is authorized to transfer from and the amount. Applicable to allowance transfers only.
addApprovedTokenTransfer(<tokenId>, <accountId>, <value>)TokenId, AccountId, longThe 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, intThe 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, AccountId, AccountIdThe 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.
addHbarTransferWithHook(<accountId>, <amount>, <hookCall>)AccountId, Hbar, FungibleHookCallAdds an HBAR transfer with an attached account allowance hook call. The FungibleHookType on the hook call determines sender/receiver role and pre/pre-post mode. See Hiero Hooks.
addTokenTransferWithHook(<tokenId>, <accountId>, <amount>, <hookCall>)TokenId, AccountId, long, FungibleHookCallAdds a fungible token transfer with an attached account allowance hook call. See Hiero Hooks.
addNftTransferWithHook(<nftId>, <sender>, <receiver>, <senderHookCall>, <receiverHookCall>)NftId, AccountId, AccountId, NftHookCall, NftHookCallAdds an NFT transfer with optional sender and/or receiver hook calls. Pass null for either hook call if not needed. See Hiero Hooks.
// Create a transaction to transfer 1 HBAR 
TransferTransaction transaction = new TransferTransaction()
     .addHbarTransfer(OPERATOR_ID, new Hbar(-1))
     .addHbarTransfer(newAccountId, evmAddress, new Hbar(1));

//Submit the transaction to a Hedera network
TransactionResponse txResponse = transaction.execute(client);

//Request the receipt of the transaction
TransactionReceipt receipt = txResponse.getReceipt(client);

//Get the transaction consensus status
Status transactionStatus = receipt.status;

System.out.println("The transaction consensus status is " +transactionStatus);

//Version 2.0.0

Transfer with account allowance hooks

The following examples demonstrate how to invoke Hiero Hooks during a transfer. Each WithHook method attaches a hook call to a specific transfer entry. The hook’s EVM bytecode executes and must return true for the transfer to succeed.

Hook call types

Hooks use typed call objects that extend a base HookCall:
ClassUsed ForHook Type Enum
FungibleHookCallHBAR and fungible token transfersFungibleHookType: PRE_HOOK_SENDER, PRE_POST_HOOK_SENDER, PRE_HOOK_RECEIVER, PRE_POST_HOOK_RECEIVER
NftHookCallNFT transfersNftHookType: PRE_HOOK, PRE_POST_HOOK
Each hook call requires a hookId (the 64-bit ID of the hook on the owning account) and an EvmHookCall containing data (extra bytes passed to the hook) and gasLimit (maximum gas the payer will pay for this hook).

Example: HBAR transfer with a pre-hook

// Define the hook call
FungibleHookCall senderHook = new FungibleHookCall()
    .setHookId(1001L)
    .setEvmHookCall(
        new EvmHookCall()
            .setData(new byte[]{0x01, 0x02})
            .setGasLimit(50000L)
    )
    .setHookType(FungibleHookType.PRE_HOOK_SENDER);

// Build the transfer with the hook reference
TransactionResponse response = new TransferTransaction()
    .addHbarTransferWithHook(senderAccountId, Hbar.from(-100), senderHook)
    .addHbarTransfer(receiverAccountId, Hbar.from(100))
    .freezeWith(client)
    .sign(senderKey)
    .execute(client);

TransactionReceipt receipt = response.getReceipt(client);
System.out.println("Transfer with hook: " + receipt.status);

Example: NFT transfer with sender and receiver hooks

NftId nftId = new NftId(TokenId.fromString("0.0.12345"), 1);

NftHookCall senderHook = new NftHookCall()
    .setHookId(1002L)
    .setEvmHookCall(new EvmHookCall()
        .setData(new byte[]{0x03, 0x04})
        .setGasLimit(60000L))
    .setHookType(NftHookType.PRE_HOOK);

NftHookCall receiverHook = new NftHookCall()
    .setHookId(1003L)
    .setEvmHookCall(new EvmHookCall()
        .setData(new byte[]{0x05, 0x06})
        .setGasLimit(40000L))
    .setHookType(NftHookType.PRE_HOOK);

TransactionResponse response = new TransferTransaction()
    .addNftTransferWithHook(
        nftId,
        senderAccountId,
        receiverAccountId,
        senderHook,     // Sender hook (or null if not needed)
        receiverHook    // Receiver hook (or null if not needed)
    )
    .freezeWith(client)
    .sign(senderKey)
    .execute(client);

System.out.println("NFT transfer with hooks: " + response.getReceipt(client).status);

Example: Fungible token transfer with pre/post hook

TokenId tokenId = TokenId.fromString("0.0.54321");

FungibleHookCall prePostHook = new FungibleHookCall()
    .setHookId(1004L)
    .setEvmHookCall(new EvmHookCall()
        .setData(new byte[]{0x07, 0x08})
        .setGasLimit(70000L))
    .setHookType(FungibleHookType.PRE_POST_HOOK_SENDER);

TransactionResponse response = new TransferTransaction()
    .addTokenTransferWithHook(tokenId, senderAccountId, -1000L, prePostHook)
    .addTokenTransfer(tokenId, receiverAccountId, 1000L)
    .freezeWith(client)
    .sign(senderKey)
    .execute(client);

System.out.println("Token transfer with pre/post hook: " + response.getReceipt(client).status);

Hook execution order

When a TransferTransaction invokes multiple hooks, the network executes them in a strict order:
  1. Pre-hooks: All PRE_HOOK_SENDER / PRE_HOOK_RECEIVER hooks execute in the order their transfers appear (HBAR first, then each token transfer list). For NFT transfers with both sender and receiver hooks, the sender hook executes first.
  2. Pre/Post hooks (pre-transfer call): All PRE_POST_HOOK variants execute their allowPre(...) function, in the same transfer order.
  3. Main transfer logic executes.
  4. Pre/Post hooks (post-transfer call): The same hooks execute their allowPost(...) function, in the same order as step 2.

Get transaction values

MethodTypeDescription
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
// Create a transaction 
CryptoTransferTransaction transaction = new CryptoTransferTransaction()
    .addSender(OPERATOR_ID, new Hbar(1)
    .addRecipient(newAccountId, new Hbar(1));

//Get transfers
List<Transfer> transfers = transaction.getTransfers();

//v2.0.0