Skip to content

Commit b867b62

Browse files
authored
chore: refactor topic_delete_transaction to use Client.from_env() (hiero-ledger#1971)
Signed-off-by: greywolf8 <arkapravapanigrahi798080@gmail.com>
1 parent aa22a12 commit b867b62

2 files changed

Lines changed: 13 additions & 31 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.
2121
### Examples
2222
- Updated the `examples/consensus/topic_create_transaction_revenue_generating.py` example to use `Client.from_env()` for simpler client setup. (#1964)
2323

24+
- Refactored `examples/consensus/topic_delete_transaction.py` to use Client.from_env() for simplified client initialization, removed manual setup code, and cleaned up unused imports (`os`, `AccountId`, `PrivateKey`). (`#1971`)
25+
2426
### Tests
2527

2628
### Docs

examples/consensus/topic_delete_transaction.py

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,47 +9,27 @@
99
- topic_delete_transaction() performs the create+delete transaction steps
1010
- main() orchestrates setup and calls helper functions
1111
"""
12-
import os
13-
import sys
1412

15-
from dotenv import load_dotenv
13+
import sys
1614

1715
from hiero_sdk_python import (
18-
AccountId,
1916
Client,
20-
Network,
21-
PrivateKey,
2217
ResponseCode,
2318
TopicCreateTransaction,
2419
TopicDeleteTransaction,
2520
)
21+
from hiero_sdk_python.account.account_id import AccountId
22+
from hiero_sdk_python.crypto.private_key import PrivateKey
2623

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)
3724

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
5333

5434

5535
def create_topic(client, operator_key):

0 commit comments

Comments
 (0)