Hedera
Search…
Transfer tokens
Transfer tokens from some accounts to other accounts. The transaction must be signed by the sending account. Each negative amount is withdrawn from the corresponding account (a sender), and each positive one is added to the corresponding account (a receiver). All amounts must have a sum of zero. This does not apply to NFT token transfers. Each amount is a number with the lowest denomination possible for a token. Example: Token X has 2 decimals. Account A transfers an amount of 100 tokens by providing 10000 as the amount in the TransferList. If Account A wants to send 100.55 tokens, he must provide 10055 as the amount. If any sender account fails to have a sufficient token balance, then the entire transaction fails and none of the transfers occur, though the transaction fee is still charged.
Custom Fee Tokens
Custom fee tokens are tokens that have a unique custom fee schedule associated to them. The sender account is required to pay for the custom fee(s) associated with the token that is being transferred. The sender account must have the amount of the custom fee token being transferred and the custom fee amounts to successfully process the transaction. You can check to see if the token has a custom fee schedule by requesting the token info query. Token with custom fees allow up two levels of nesting in a transfer transaction.
Note: Accounts must be either be associated with the HTS token or have available auto token association slots before tokens can be transferred to it. You will not be able to utilize the token auto association slots in the 0.18 release. The full feature will be available in 0.20.0.
    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.

Transaction Signing Requirements:

    The key of the account sending the tokens
    The transaction fee payer account key
Constructor
Description
new TransferTransaction()
Initializes a TransferTransaction object
1
new TransferTransaction()
Copied!

Methods

V2
V1
Method
Type
Description
addHbarTransfer(<accountId, value>)
AccountID, Hbar/long
Add the from and to account to transfer hbars (you will need to call this method twice). The sending account must sign the transaction. The sender and recipient values must net zero.
addTokenTransfer(<tokenId, accountId,value>)
TokenId, AccountId, long
Add the from and to account to transfer tokens (you will need to call this method twice). The ID of the token, the account ID to transfer the tokens from or to, and the value of the token to transfer. The sender and recipient values must net zero.
addNftTransfer(<nftId, sender, receiver)
NftId, AccountId, AccountId
The NFT ID being transferred, the account ID the NFT owner, the account ID of the receiver of the NFT.
Java
1
//Create the transfer transaction
2
TransferTransaction transaction = new TransferTransaction()
3
.addTokenTransfer(tokenId, OPERATOR_ID, -10)
4
.addTokenTransfer(tokenId, accountId, 10);
5
6
//Sign with the client operator key and 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
//v2.0.1
Copied!
JavaScript
1
//Create the transfer transaction
2
const transaction = await new TransferTransaction()
3
.addTokenTransfer(tokenId, accountId1, -10)
4
.addTokenTransfer(tokenId, accountId2, 10)
5
.freezeWith(client);
6
7
//Sign with the sender account private key
8
const signTx = await transaction.sign(accountKey1);
9
10
//Sign with the client operator private key and submit to a Hedera network
11
const txResponse = await signTx.execute(client);
12
13
//Request the receipt of the transaction
14
const receipt = await txResponse.getReceipt(client);
15
16
//Obtain the transaction consensus status
17
const transactionStatus = receipt.status;
18
19
console.log("The transaction consensus status " +transactionStatus.toString());
20
21
//v2.0.5
Copied!
Go
1
//Create the transfer transaction and freeze the transaction from further modification
2
transaction, err := hedera.NewTransferTransaction().
3
AddTokenTransfer(tokenId, accountId1, -10).
4
AddTokenTransfer(tokenId, accountId2, 10).
5
FreezeWith(client)
6
7
//Sign with the accountId1 private key, sign with the client operator key and submit to a Hedera network
8
txResponse, err := transaction.Sign(accountKey1).Execute(client)
9
10
if err != nil {
11
panic(err)
12
}
13
14
//Request the receipt of the transaction
15
receipt, err := txResponse.GetReceipt(client)
16
if err != nil {
17
panic(err)
18
}
19
20
//Get the transaction consensus status
21
status := receipt.Status
22
23
fmt.Printf("The transaction consensus status is %v\n", status)
24
//v2.1.0
Copied!
Method
Type
Description
addHbarTransfer(<accountId, value>)
AccountID, Hbar/long
Add the from and to account to transfer hbars (you will need to call this method twice). The sending account must sign the transaction. The sender and recipient values must net zero.
addTokenTransfer(<tokenId, accountId,value>)
TokenId, AccountId, long
Add the from and to account to transfer tokens (you will need to call this method twice).The ID of the token, the account ID to transfer the tokens from or to, and the value of the token to transfer. The sender and recipient values must net zero.
addNftTransfer(<nftId, sender, receiver)
NftId, AccountId, AccountId
The NFT ID being transferred, the account ID the NFT owner, the account ID of the receiver of the NFT.
Java
1
//Create the transfer transaction
2
TransferTransaction transaction = new TransferTransaction()
3
.addTokenTransfer(tokenId, accountId, -10)
4
.addTokenTransfer(tokenId, OPERATOR_ID, 10);
5
6
7
//Sign with the client operator key and submit the transaction to a Hedera network
8
TransactionId txId = transaction.build(client).sign(accountKey).execute(client);
9
10
//Request the receipt of the transaction
11
TransactionReceipt receipt = txId.getReceipt(client);
12
13
//Get the transaction consensus status
14
Status transactionStatus = receipt.status;
15
16
System.out.println("The transaction consensus status is " +transactionStatus);
17
18
//v1.3.2
Copied!
JavaScript
1
//Transfer 100 tokens between two accounts
2
const transaction = new TransferTransaction()
3
.addTokenTransfer(tokenId, accountId, -100)
4
.addTokenTransfer(tokenId, OPERATOR_ID, 100);
5
6
//Build the unsigned transaction, sign with sender account private key, submit the transaction to a Hedera network
7
const transactionId = await transaction.build(client).sign(accountKey).execute(client);
8
9
//Request the receipt of the transaction
10
const getReceipt = await transactionId.getReceipt(client);
11
12
//Obtain the transaction consensus status
13
const transactionStatus = getReceipt.status;
14
15
console.log("The transaction consensus status " +transactionStatus);
Copied!
Last modified 6d ago
Copy link
Contents
Methods