Get account token balance

Get the token balances for a given account.

V2
V1
V2

Constructor

Description

new AccountBalanceQuery()

Initializes the AccountBalanceQuery object

new AccountBalanceQuery()

Method

Type

Requirement

setAccountId(<tokenId>)

TokenId

Required

Java
//Create the query
AccountBalanceQuery query = new AccountBalanceQuery()
.setAccountId(accountId);
//Sign with the operator private key and submit to a Hedera network
AccountBalance tokenBalance = query.execute(client);
System.out.println("The token balance(s) for this account: " +tokenBalance.token);
//v2.0.1
JavaScript
//Create the query
const query = new AccountBalanceQuery()
.setAccountId(accountId);
//Sign with the client operator private key and submit to a Hedera network
const tokenBalance = await query.execute(client);
console.log("The token balance(s) for this account: " +tokenBalance.tokens.toString());
//v2.0.7
Go
//Create the query
query := hedera.NewAccountBalanceQuery().
SetAccountID(accountId)
//Sign with the client operator private key and submit to a Hedera network
tokenbalance, err := query.Execute(client)
if err != nil {
panic(err)
}
fmt.Printf("The token balance(s) for this account: %v\n", tokenBalance)
//v2.1.0
V1

Constructor

Description

new TokenBalanceQuery()

Initializes the TokenBalanceQuery object

new TokenBalanceQuery()

Method

Type

Requirement

setAccountId(<tokenId>)

TokenId

Required

Java
Map<TokenId, Long> tokenBalance = new TokenBalanceQuery()
.setAccountId(accountId)
.execute(client);
System.out.println("The token balance(s) for this account: " +tokenBalance);
//Version: 1.2.2
JavaScript
const tokenBalance = await new TokenBalanceQuery()
.setAccountId(accountId)
.execute(client);
console.log("The token balance(s) for this account: " +tokenBalance.get("<tokenId>"));
//Version 1.4.2