Hedera
Search…
Queries
Queries are requests that do not require network consensus. Queries are processed only by the single node the request is sent to. Below is a list of network queries by service.
Cryptocurrency Accounts
Consensus
Tokens
File Service
Smart Contracts

Get Query Cost

A query that returns the cost of a query prior to submitting the query to network node for processing. If the cost of the query greater than the default max query payment (1 hbar) you can use setMaxQueryPayment(<hbar>) to change the default.
V2
V1
Method
Type
Description
getCost(<client>)
Client
Get the cost of the query in Hbar
getCost(<client, timeout>)
Client, Duration
The max length of time the sdk will attempt to retry for in the event of repeated busy responses from node(s)
getCostAsync(<client>)
Client
Get the cost of a query asynchronously
Java
1
//Create the query request
2
AccountBalanceQuery query = new AccountBalanceQuery()
3
.setAccountId(accountId);
4
5
//Get the cost of the query
6
Hbar queryCost = query.getCost(client);
7
8
System.out.println("The account balance query cost is " +queryCost);
9
10
//v2.0.0
Copied!
JavaScript
1
//Create the query request
2
const query = new AccountBalanceQuery()
3
.setAccountId(accountId);
4
5
//Get the cost of the query
6
const queryCost = await query.getCost(client);
7
8
console.log("The account balance query cost is " +queryCost);
9
10
//v2.0.0
Copied!
Go
1
//Create the query request
2
query := hedera.NewAccountBalanceQuery().
3
SetAccountID(newAccountId)
4
5
//Get the cost of the query
6
cost, err := query.GetCost(client)
7
8
if err != nil {
9
panic(err)
10
}
11
12
fmt.Printf("The account balance query cost is: %v\n ", cost.String())
13
14
//v2.0.0
Copied!
Method
Type
Description
getCost(<client>)
Client
Get the cost of the query in long representation
getCostAsync(<client, withCost, onError>)
Client, Consumer<long>, Consumer<HederaThrowable>
Get the cost of a query asynchronously
Java
1
//Create the query request
2
AccountBalanceQuery query = new AccountBalanceQuery()
3
.setAccountId(accountId);
4
5
//Get the cost of the query
6
long queryCost = query.getCost(client);
7
8
System.out.println("The account balance query cost is " +queryCost);
9
10
//v1.3.2
Copied!
JavaScript
1
//Create the query request
2
const query = new AccountBalanceQuery()
3
.setAccountId(accountId);
4
5
//Get the cost of the query
6
const queryCost = await query.getCost(client);
7
8
console.log("The account balance query cost is " +queryCost);
Copied!

Last modified 6d ago
Copy link