Skip to content

Commit cbebd59

Browse files
committed
chore: improve example
Signed-off-by: Manish Dait <daitmanish88@gmail.com>
1 parent 3c3628c commit cbebd59

File tree

1 file changed

+31
-8
lines changed

1 file changed

+31
-8
lines changed

examples/transaction/transaction_without_wait_for_receipt.py

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@
88

99
import 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

1619
def 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+
2545
def 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("\n1.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("\n2.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

Comments
 (0)