88
99import sys
1010
11- from hiero_sdk_python import Client , AccountCreateTransaction
12- from hiero_sdk_python .crypto .private_key import PrivateKey
13- from hiero_sdk_python .response_code import ResponseCode
11+ from hiero_sdk_python import (
12+ Client ,
13+ AccountCreateTransaction ,
14+ PrivateKey ,
15+ ResponseCode
16+ )
1417
1518
1619def build_transaction () -> AccountCreateTransaction :
@@ -22,6 +25,23 @@ def build_transaction() -> AccountCreateTransaction:
2225 return AccountCreateTransaction ().set_key_without_alias (key ).set_initial_balance (1 )
2326
2427
28+ def print_transaction_record (record ):
29+ """Print the transaction record"""
30+ print (f"Transaction ID: { record .transaction_id } " )
31+ print (f"Transaction Fee: { record .transaction_fee } " )
32+ print (f"Transaction Hash: { record .transaction_hash .hex ()} " )
33+ print (f"Transaction Memo: { record .transaction_memo } " )
34+ print (f"Transaction Account ID: { record .receipt .account_id } " )
35+
36+
37+ def print_transaction_receipt (receipt ):
38+ if receipt .status != ResponseCode .SUCCESS :
39+ raise RuntimeError (f"Receipt Query failed with status: { ResponseCode (receipt .status ).name } " )
40+
41+ print (f"Transaction Receipt Status: { ResponseCode (receipt .status ).name } " )
42+ print (f"Transaction Account ID: { receipt .account_id } " )
43+
44+
2545def main ():
2646 """
2747 1. Initialize a client from environment variables (operator required in env).
@@ -33,22 +53,25 @@ def main():
3353 client = Client .from_env ()
3454 tx = build_transaction ()
3555
56+ print ("Executing transaction..." )
3657 # Execute the transaction without waiting for receipt immediately
3758 response = tx .execute (client , wait_for_receipt = False )
3859
3960 print ("Transaction executed successfully!" )
4061 print (f"Transaction submitted with ID: { response .transaction_id } " )
4162
4263 # Retrieve receipt and record after submission
64+ print ("\n 1.Getting Transaction Receipt using Transaction Response..." )
4365 receipt = response .get_receipt (client )
44- print ( f"Receipt status: { ResponseCode ( receipt . status ). name } " )
45-
66+ print_transaction_receipt ( receipt )
67+
4668
69+ print ("\n 2.Getting Transaction Record using Transaction Response..." )
4770 record = response .get_record (client )
48- print ( "Record:" , record )
71+ print_transaction_record ( record )
4972
50- except Exception as exc :
51- print (f"Error during transaction execution : { exc } " )
73+ except Exception as err :
74+ print (f"Error during transaction: { err } " )
5275 sys .exit (1 )
5376
5477
0 commit comments