Skip to content

Latest commit

 

History

History
71 lines (52 loc) · 1.99 KB

get-account-token-balance.md

File metadata and controls

71 lines (52 loc) · 1.99 KB

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.

Query Fees

  • Please see the transaction and query fees table for the base transaction fee
  • Please use the Hedera fee estimator to estimate your query fee cost
Constructor Description
new AccountBalanceQuery() Initializes the AccountBalanceQuery object
new AccountBalanceQuery()
Method Type Requirement
setAccountId(<accountId>) AccountId Required

{% tabs %} {% tab title="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.tokens);

//v2.0.9

{% endtab %}

{% tab title="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

{% endtab %}

{% tab title="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

{% endtab %} {% endtabs %}