Query Ledger Data

Summary

In this section, we will guide you through the steps of querying your account balance, enabling you to retrieve the most current information about the available funds in your new Hedera account.

Prerequisites:

Note: You can always check the "Code Check ✅ " section at the bottom of each page to view the entire code if you run into issues. You can also post your issue to the respective SDK channel in our Discord community here or on the GitHub repository here.

Query the account balance

Get the cost of requesting the query

You can request the cost of a query prior to submitting the query to the Hedera network. Checking an account balance is free of charge today. You can verify that by the method below.

//Request the cost of the query
Hbar queryCost = new AccountBalanceQuery()
     .setAccountId(newAccountId)
     .getCost(client);

System.out.println("The cost of this query is: " +queryCost);

Get the account balance

You will verify the account balance was updated for the new account by requesting a get account balance query. The current account balance should be the sum of the initial balance (1,000 tinybars) plus the transfer amount (1,000 tinybars) and equal to 2,000 tinybars.

Code Check ✅

Your complete code file should look something like this:

Java
JavaScript
Go

Sample output:

Have a question? Ask it on StackOverflow

Last updated