@@ -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