Skip to content

Commit 07320c7

Browse files
committed
Fix: Examples Only
Signed-off-by: aceppaluni <aceppaluni@gmail.com>
1 parent 44bd0bc commit 07320c7

2 files changed

Lines changed: 11 additions & 12 deletions

File tree

examples/query/account_balance_query.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def get_balance(account_id: AccountId):
122122
with urlopen(request, timeout=10) as response:
123123
data = json.load(response)
124124

125-
balance_tinybars = data["balance"]
125+
balance_tinybars = data["balance"]["balance"]
126126
balance_hbars = balance_tinybars / 100_000_000
127127

128128
print("✓ Account balance retrieved successfully")

examples/query/account_balance_query_2.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def get_account_balance(account_id: AccountId):
128128
with urlopen(request, timeout=10) as response:
129129
data = json.load(response)
130130

131-
hbar_balance = data["balance"] / 100_000_000
131+
hbar_balance = data["balance"]["balance"] / 100_000_000
132132

133133
print("✅ Account balance retrieved successfully!")
134134
print(f"💰 HBAR Balance for {account_id}: {hbar_balance} hbars")
@@ -149,17 +149,16 @@ def get_token_balance(balance_data, token_id: TokenId):
149149
return 0
150150

151151

152-
# OPTIONAL comparison function
153-
def compare_token_balances(client, treasury_id: AccountId, receiver_id: AccountId, token_id: TokenId):
152+
def compare_token_balances(treasury_id: AccountId, receiver_id: AccountId, token_id: TokenId):
154153
"""Compare token balances between two accounts."""
155154
print(f"\n🔎 Comparing token balances for Token ID {token_id} between accounts {treasury_id} and {receiver_id}...")
156-
# retrieve balances for both accounts
157-
treasury_balance = get_account_balance(client, treasury_id)
158-
receiver_balance = get_account_balance(client, receiver_id)
159-
# extract token balances
160-
treasury_token_balance = treasury_balance.token_balances.get(token_id, 0)
161-
receiver_token_balance = receiver_balance.token_balances.get(token_id, 0)
162-
# print results
155+
156+
treasury_balance = get_account_balance(treasury_id)
157+
receiver_balance = get_account_balance(receiver_id)
158+
159+
treasury_token_balance = get_token_balance(treasury_balance, token_id)
160+
receiver_token_balance = get_token_balance(receiver_balance, token_id)
161+
163162
print(f"🏷️ Token balance for Treasury ({treasury_id}): {treasury_token_balance}")
164163
print(f"🏷️ Token balance for Receiver ({receiver_id}): {receiver_token_balance}")
165164

@@ -181,7 +180,7 @@ def main():
181180
# will be owned by the test account and show up in its token balances.
182181
token_id = create_and_mint_token(test_account_id, test_account_key, client)
183182
# Retrieve and display account balance for the test account
184-
get_account_balance(client, test_account_id)
183+
get_account_balance(test_account_id)
185184
# OPTIONAL comparison of token balances between test account and operator account
186185
compare_token_balances(client, test_account_id, client.operator_account_id, token_id)
187186

0 commit comments

Comments
 (0)