Skip to content

Commit 1f7e427

Browse files
authored
refactor: use Client.from_env() in contract_delete_transaction example (hiero-ledger#1823)
Signed-off-by: Raj <sinhars303@gmail.com>
1 parent a428a1b commit 1f7e427

2 files changed

Lines changed: 12 additions & 16 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.
1616

1717
### Examples
1818

19+
- Refactored contract_delete_transaction example to use Client.from_env. (#1823)
20+
1921
### Docs
2022
- Improved Google-style docstring for `compress_point_unchecked` in `crypto_utils.py`. (#1625)
2123
- chore: update office hours and community calls to use direct links (`#1804`)

examples/contract/contract_delete_transaction.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@
2020
uv run -m examples.contract.contract_delete_transaction
2121
python -m examples.contract.contract_delete_transaction
2222
"""
23-
import os
23+
2424
import sys
2525

26-
from dotenv import load_dotenv
2726

28-
from hiero_sdk_python import AccountId, Client, Network, PrivateKey
27+
28+
from hiero_sdk_python import Client
29+
2930
from hiero_sdk_python.contract.contract_create_transaction import (
3031
ContractCreateTransaction,
3132
)
@@ -41,22 +42,15 @@
4142
# The contract bytecode is pre-compiled from Solidity source code
4243
from .contracts import SIMPLE_CONTRACT_BYTECODE
4344

44-
load_dotenv()
45-
46-
network_name = os.getenv("NETWORK", "testnet").lower()
4745

4846

49-
def setup_client():
50-
"""Initialize and set up the client with operator account."""
51-
network = Network(network_name)
52-
print(f"Connecting to Hedera {network_name} network!")
53-
client = Client(network)
54-
55-
operator_id = AccountId.from_string(os.getenv("OPERATOR_ID", ""))
56-
operator_key = PrivateKey.from_string(os.getenv("OPERATOR_KEY", ""))
57-
client.set_operator(operator_id, operator_key)
47+
def setup_client() -> Client:
48+
"""
49+
Set up and configure the client by loading OPERATOR_ID and OPERATOR_KEY with Client.from_env().
50+
"""
51+
client = Client.from_env()
52+
print(f"Connecting to Hedera {client.network.network} network!")
5853
print(f"Client set up with operator id {client.operator_account_id}")
59-
6054
return client
6155

6256

0 commit comments

Comments
 (0)