Hedera
Search…
Get account token balance
To get the balance of tokens for an account, you can submit an account balance query. The account balance query will return the tokens the account holds in a list format.
V2
V1
Constructor
Description
new AccountBalanceQuery()
Initializes the AccountBalanceQuery object
1
new AccountBalanceQuery()
Copied!
Method
Type
Requirement
setAccountId(<accountId>)
AccountId
Required
Java
1
//Create the query
2
AccountBalanceQuery query = new AccountBalanceQuery()
3
.setAccountId(accountId);
4
5
//Sign with the operator private key and submit to a Hedera network
6
AccountBalance tokenBalance = query.execute(client);
7
8
System.out.println("The token balance(s) for this account: " +tokenBalance.tokens);
9
10
//v2.0.9
Copied!
JavaScript
1
//Create the query
2
const query = new AccountBalanceQuery()
3
.setAccountId(accountId);
4
5
//Sign with the client operator private key and submit to a Hedera network
6
const tokenBalance = await query.execute(client);
7
8
console.log("The token balance(s) for this account: " +tokenBalance.tokens.toString());
9
10
//v2.0.7
Copied!
Go
1
//Create the query
2
query := hedera.NewAccountBalanceQuery().
3
SetAccountID(accountId)
4
5
//Sign with the client operator private key and submit to a Hedera network
6
tokenbalance, err := query.Execute(client)
7
8
if err != nil {
9
panic(err)
10
}
11
12
fmt.Printf("The token balance(s) for this account: %v\n", tokenBalance)
13
14
//v2.1.0
Copied!
Constructor
Description
new TokenBalanceQuery()
Initializes the TokenBalanceQuery object
1
new TokenBalanceQuery()
Copied!
Method
Type
Requirement
setAccountId(<accountId>)
AccountId
Required
Java
1
Map<TokenId, Long> tokenBalance = new TokenBalanceQuery()
2
.setAccountId(accountId)
3
.execute(client);
4
5
System.out.println("The token balance(s) for this account: " +tokenBalance);
6
//Version: 1.2.2
Copied!
JavaScript
1
const tokenBalance = await new TokenBalanceQuery()
2
.setAccountId(accountId)
3
.execute(client);
4
5
console.log("The token balance(s) for this account: " +tokenBalance.get("<tokenId>"));
6
//Version 1.4.2
Copied!
Last modified 6d ago
Copy link