Skip to content

Commit cb161d0

Browse files
committed
feat: Deprecate AccountBalanceQuery
Signed-off-by: aceppaluni <aceppaluni@gmail.com>
1 parent 38309b9 commit cb161d0

7 files changed

Lines changed: 229 additions & 216 deletions

File tree

docs/sdk_users/running_examples.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,26 @@ You can choose either syntax or even mix both styles in your projects.
9292

9393
### Querying Account Balance
9494

95+
> **Deprecated:** `CryptoGetAccountBalanceQuery` is no longer supported.
96+
> The `CryptoGetBalance` endpoint is scheduled for removal with consensus
97+
> node release 77 (estimated September 2026). Use the Mirror Node REST API
98+
> instead, for example `GET /api/v1/accounts/{accountId}`.
99+
100+
The following examples demonstrate the deprecated SDK call path and will
101+
raise an error when executed.
102+
95103
#### Pythonic Syntax:
96-
```
97-
balance = CryptoGetAccountBalanceQuery(account_id=some_account_id).execute(client) print(f"Account balance: {balance.hbars} hbars")
104+
```python
105+
balance = CryptoGetAccountBalanceQuery(account_id=some_account_id).execute(client)
98106
```
99107

100108
#### Method Chaining:
101109
```
102-
balance = ( CryptoGetAccountBalanceQuery() .set_account_id(some_account_id) .execute(client) ) print(f"Account balance: {balance.hbars} hbars")
110+
balance = (
111+
CryptoGetAccountBalanceQuery()
112+
.set_account_id(some_account_id)
113+
.execute(client)
114+
)
103115
```
104116

105117
### Creating an Account

examples/query/account_balance_query.py

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
11
"""
2-
3-
42
Query Balance Example.
53
6-
This script demonstrates how to:
7-
1. Set up a client connection to the Hedera network
8-
2. Create a new account with an initial balance
9-
3. Query account balance
10-
4. Transfer HBAR between accounts
11-
12-
Run with:
13-
uv run examples/query/account_balance_query.py
14-
python examples/query/account_balance_query.py
4+
.. deprecated::
5+
CryptoGetAccountBalanceQuery is no longer supported. Use the Mirror Node
6+
REST API, for example GET /api/v1/accounts/{accountId}, to retrieve
7+
account balances.
158
9+
...
1610
"""
1711

1812
import sys
@@ -88,23 +82,16 @@ def create_account(client, operator_key, initial_balance=Hbar(10)):
8882

8983
def get_balance(client, account_id):
9084
"""
91-
Query and retrieve the HBAR balance of an account.
92-
93-
Args:
94-
client (Client): The Hiero SDK client.
95-
account_id (AccountId): The account ID to query.
85+
Demonstrate the deprecated account balance query.
9686
97-
Returns:
98-
Hbar: The account's current balance in HBAR.
87+
.. deprecated::
88+
CryptoGetAccountBalanceQuery is no longer supported. Use the
89+
Mirror Node REST API, for example GET /api/v1/accounts/{accountId}.
9990
"""
10091
print(f"Querying balance for account {account_id}...")
10192

10293
balance_query = CryptoGetAccountBalanceQuery().set_account_id(account_id)
103-
balance = balance_query.execute(client)
104-
105-
balance_hbar = balance.hbars.to_hbars()
106-
print(f"✓ Balance retrieved: {balance_hbar} hbars\n")
107-
return balance_hbar
94+
return balance_query.execute(client)
10895

10996

11097
def transfer_hbars(client, operator_id, operator_key, recipient_id, amount):
@@ -157,6 +144,8 @@ def main():
157144
print("INITIAL BALANCE CHECK")
158145
print("=" * 60)
159146
initial_balance = get_balance(client, new_account_id)
147+
if initial_balance is None:
148+
print(f"Use the Mirror Node REST API instead, for example GET /api/v1/accounts/{new_account_id}.")
160149
print(f"Initial balance of new account: {initial_balance} hbars")
161150
print("=" * 60 + "\n")
162151

examples/query/account_balance_query_2.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
# python examples/query/account_balance_query_2.py
33

44
"""
5-
6-
Example: Use CryptoGetAccountBalanceQuery to retrieve an account's.
7-
8-
HBAR and token balances, including minting NFTs to the account.
5+
.. deprecated::
6+
CryptoGetAccountBalanceQuery is no longer supported. Use the Mirror Node
7+
REST API, for example GET /api/v1/accounts/{accountId}, to retrieve
8+
account balances.
99
"""
1010

1111
import os

src/hiero_sdk_python/query/account_balance_query.py

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import logging
4+
import warnings
45
from typing import Any
56

67
from hiero_sdk_python.account.account_balance import AccountBalance
@@ -18,24 +19,24 @@
1819

1920
class CryptoGetAccountBalanceQuery(Query):
2021
"""
21-
A query to retrieve the balance of a specific account from the Hedera network.
22+
Query an account's balance.
2223
23-
This class constructs and executes a query to obtain the balance of an account,
24-
including hbars and tokens.
24+
.. deprecated::
25+
The CryptoGetBalance endpoint is scheduled for removal with the
26+
consensus node release 77 (estimated September 2026). Use the Mirror
27+
Node REST API to retrieve account balances instead.
2528
"""
2629

2730
def __init__(
2831
self,
2932
account_id: AccountId | None = None,
3033
contract_id: ContractId | None = None,
3134
) -> None:
32-
"""
33-
Initializes a new instance of the CryptoGetAccountBalanceQuery class.
34-
35-
Args:
36-
account_id (AccountId, optional): The ID of the account to retrieve the balance for.
37-
contract_id (ContractId, optional): The ID of the contract to retrieve the balance for.
38-
"""
35+
warnings.warn(
36+
"Deprecated: AccountBalanceQuery will stop working when the Hedera network removes the CryptoGetBalance endpoint (estimated September 2026, consensus node release 77). Use the mirror node REST API to retrieve account balances.",
37+
DeprecationWarning,
38+
stacklevel=2,
39+
)
3940
super().__init__()
4041
self.account_id: AccountId | None = None
4142
self.contract_id: ContractId | None = None
@@ -133,25 +134,20 @@ def _get_method(self, channel: _Channel) -> _Method:
133134

134135
def execute(self, client: Client, timeout: int | float | None = None) -> AccountBalance:
135136
"""
136-
Executes the account balance query.
137-
138-
This function delegates the core logic to `_execute()`, and may propagate exceptions raised by it.
137+
Execute the account balance query.
139138
140-
Sends the query to the Hedera network and processes the response
141-
to return an AccountBalance object.
142-
143-
Args:
144-
client (Client): The client instance to use for execution
145-
timeout (Optional[Union[int, float]]): The total execution timeout (in seconds) for this execution.
146-
147-
Returns:
148-
AccountBalance: The account balance from the network
139+
.. deprecated::
140+
The CryptoGetBalance endpoint is scheduled for removal with the
141+
consensus node release 77 (estimated September 2026). Use the Mirror
142+
Node REST API to retrieve account balances instead.
149143
150144
Raises:
151-
PrecheckError: If the query fails with a non-retryable error
152-
MaxAttemptsError: If the query fails after the maximum number of attempts
153-
ReceiptStatusError: If the query fails with a receipt status error
145+
RuntimeError: Always, because the AccountBalanceQuery is no longer
146+
supported.
154147
"""
148+
raise RuntimeError(
149+
"Error: AccountBalanceQuery is no longer supported. Use the mirror node REST API to retrieve account balances."
150+
)
155151
self._before_execute(client)
156152
response = self._execute(client, timeout)
157153

tck/handlers/account.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,10 @@ def delete_account(params: DeleteAccountParams) -> DeleteAccountResponse:
266266

267267
@rpc_method("getAccountBalance")
268268
def get_account_balance(params: GetAccountBalanceParams) -> GetAccountBalanceResponse:
269-
"""Get account balance for an account."""
269+
"""Get account balance for an account.
270+
271+
Deprecated: use the Mirror Node REST API instead.
272+
"""
270273
client = get_client(params.sessionId)
271274

272275
query = CryptoGetAccountBalanceQuery().set_grpc_deadline(DEFAULT_GRPC_TIMEOUT)
@@ -276,7 +279,14 @@ def get_account_balance(params: GetAccountBalanceParams) -> GetAccountBalanceRes
276279
if params.contractId is not None:
277280
query.set_contract_id(ContractId.from_string(params.contractId))
278281

279-
account_balance = query.execute(client)
282+
try:
283+
account_balance = query.execute(client)
284+
except RuntimeError as exc:
285+
raise RuntimeError(
286+
"Error: AccountBalanceQuery is no longer supported. "
287+
"Use the mirror node REST API to retrieve account balances."
288+
) from exc
289+
280290
return map_account_balance_response(account_balance)
281291

282292

0 commit comments

Comments
 (0)