Hedera
Search…
Get account balance
A query that returns the account balance for the specified account. Requesting an account balance is currently free of charge. Queries do not change the state of the account or require network consensus. The information is returned from a single node processing the query.
Query Fees
  • Please see the transaction and query fees table for base transaction fee
  • Please use the Hedera fee estimator to estimate your query fee cost
Query Signing Requirements
  • The client operator private key is required to sign the query request
Constructor
Description
new AccountBalanceQuery()
Initializes the AccountBalanceQuery object
1
new AccountBalanceQuery
Copied!

Methods

V2
V1
Method
Type
Description
setAccountId(<accountId>)
AccountID
The account ID to return the current balance for.
Java
1
//Create the account balance query
2
AccountBalanceQuery query = new AccountBalanceQuery()
3
.setAccountId(accountId);
4
​
5
//Sign with client operator private key and submit the query to a Hedera network
6
AccountBalance accountBalance = query.execute(client);
7
​
8
//Print the balance of hbars
9
System.out.println("The hbar account balance for this account is " +accountBalance.hbars);
10
​
11
//v2.0.0
Copied!
JavaScript
1
//Create the account balance query
2
const query = new AccountBalanceQuery()
3
.setAccountId(accountId);
4
​
5
//Submit the query to a Hedera network
6
const accountBalance = await query.execute(client);
7
​
8
//Print the balance of hbars
9
console.log("The hbar account balance for this account is " +accountBalance.hbars);
10
​
11
//v2.0.7
Copied!
Go
1
//Create the account balance query
2
query := hedera.NewAccountBalanceQuery().
3
SetAccountID(newAccountId)
4
​
5
//Sign with client operator private key and submit the query to a Hedera network
6
accountBalance, err := query.Execute(client)
7
if err != nil {
8
panic(err)
9
}
10
​
11
//Print the balance of hbars
12
fmt.Println("The hbar account balance for this account is ", accountBalance.Hbars.String())
13
//v2.0.0
Copied!
Method
Type
Description
setAccountId(<accountId>)
AccountID
The account ID to return the current balance for.
Java
1
//Create the query
2
AccountBalanceQuery query = new AccountBalanceQuery()
3
.setAccountId(newAccountId);
4
​
5
//Sign with the client operator account private key and submit to a Hedera network
6
Hbar accountBalance = query.execute(client);
7
​
8
System.out.println(accountBalance);
9
​
10
//v1.3.2
Copied!
JavaScript
1
//Create the query
2
const query = new AccountBalanceQuery()
3
.setAccountId(newAccountId);
4
​
5
//Sign with the client operator account private key and submit to a Hedera network
6
Hbar accountBalance = await query.execute(client);
7
​
8
console.log(accountBalance);
9
​
10
//v1.4.4
Copied!
​
Copy link
Contents
Methods