|
9 | 9 | - topic_delete_transaction() performs the create+delete transaction steps |
10 | 10 | - main() orchestrates setup and calls helper functions |
11 | 11 | """ |
12 | | -import os |
13 | | -import sys |
14 | 12 |
|
15 | | -from dotenv import load_dotenv |
| 13 | +import sys |
16 | 14 |
|
17 | 15 | from hiero_sdk_python import ( |
18 | | - AccountId, |
19 | 16 | Client, |
20 | | - Network, |
21 | | - PrivateKey, |
22 | 17 | ResponseCode, |
23 | 18 | TopicCreateTransaction, |
24 | 19 | TopicDeleteTransaction, |
25 | 20 | ) |
| 21 | +from hiero_sdk_python.account.account_id import AccountId |
| 22 | +from hiero_sdk_python.crypto.private_key import PrivateKey |
26 | 23 |
|
27 | | -load_dotenv() |
28 | | -network_name = os.getenv("NETWORK", "testnet").lower() |
29 | | - |
30 | | - |
31 | | -def setup_client(): |
32 | | - """Initialize and set up the client with operator account.""" |
33 | | - print(f"🌐 Connecting to Hedera {network_name}...") |
34 | | - network = Network(network_name) |
35 | | - print(f"Connecting to Hedera {network_name} network!") |
36 | | - client = Client(network) |
37 | 24 |
|
38 | | - try: |
39 | | - operator_id_str = os.getenv("OPERATOR_ID") |
40 | | - operator_key_str = os.getenv("OPERATOR_KEY") |
41 | | - if not operator_id_str or not operator_key_str: |
42 | | - print("Error: OPERATOR_ID or OPERATOR_KEY not set in .env file") |
43 | | - sys.exit(1) |
44 | | - operator_id = AccountId.from_string(operator_id_str) |
45 | | - operator_key = PrivateKey.from_string(operator_key_str) |
46 | | - client.set_operator(operator_id, operator_key) |
47 | | - print(f"Client set up with operator id {client.operator_account_id}") |
48 | | - |
49 | | - return client, operator_id, operator_key |
50 | | - except (TypeError, ValueError): |
51 | | - print("Error: Creating client, Please check your .env file") |
52 | | - sys.exit(1) |
| 25 | +def setup_client() -> tuple[Client, AccountId, PrivateKey]: |
| 26 | + """ |
| 27 | + Set up and configure the client by loading OPERATOR_ID and OPERATOR_KEY with Client.from_env(). |
| 28 | + """ |
| 29 | + client = Client.from_env() |
| 30 | + print(f"Connecting to Hedera {client.network.network} network!") |
| 31 | + print(f"Client set up with operator id {client.operator_account_id}") |
| 32 | + return client, client.operator_account_id, client.operator_private_key |
53 | 33 |
|
54 | 34 |
|
55 | 35 | def create_topic(client, operator_key): |
|
0 commit comments