Skip to content

Commit bf0e6f6

Browse files
committed
fix: resolve all the conflicts
Signed-off-by: Shivakumar <[email protected]>
1 parent 3543e6c commit bf0e6f6

File tree

2 files changed

+75
-69
lines changed

2 files changed

+75
-69
lines changed

examples/account/account_create_transaction_with_fallback_alias.py

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,36 @@
1-
"""
2-
Example: Create an account where the EVM alias is derived from the main ECDSA key.
1+
"""Example: Create an account where the EVM alias is derived from the main ECDSA key.
32
43
This demonstrates:
54
- Passing only an ECDSA PrivateKey to `set_key_with_alias`
65
- The alias being derived from the main key's EVM address (fallback behaviour)
76
87
Usage:
9-
- uv run -m examples.account.account_create_transaction_with_fallback_alias
10-
- python -m examples.account.account_create_transaction_with_fallback_alias
11-
(we use -m because we use the util `info_to_dict`)
8+
uv run examples/account/account_create_transaction_with_fallback_alias.py
9+
python examples/account/account_create_transaction_with_fallback_alias.py
1210
"""
1311

1412
import os
1513
import sys
16-
import json
17-
from dotenv import load_dotenv
1814

19-
from examples.utils import info_to_dict
15+
from dotenv import load_dotenv
2016

2117
from hiero_sdk_python import (
22-
Client,
23-
PrivateKey,
2418
AccountCreateTransaction,
25-
AccountInfoQuery,
26-
Network,
2719
AccountId,
20+
AccountInfo,
21+
AccountInfoQuery,
22+
Client,
2823
Hbar,
24+
Network,
25+
PrivateKey,
2926
)
3027

3128
load_dotenv()
3229
network_name = os.getenv("NETWORK", "testnet").lower()
3330

3431

35-
def setup_client():
36-
"""Setup Client."""
32+
def setup_client() -> Client:
33+
"""Set up the Hedera client."""
3734
network = Network(network_name)
3835
print(f"Connecting to Hedera {network_name} network!")
3936
client = Client(network)
@@ -61,15 +58,15 @@ def generate_fallback_key() -> PrivateKey:
6158
sys.exit(1)
6259

6360
print(f"✅ Account ECDSA public key: {account_public_key}")
64-
print(f"✅ Derived EVM address: {evm_address}")
61+
print(f"✅ Derived EVM address: {evm_address}")
62+
6563
return account_private_key
6664

6765

68-
def create_account_with_fallback_alias(
69-
client: Client, account_private_key: PrivateKey
70-
) -> AccountId:
66+
def create_account_with_fallback_alias(client: Client, account_private_key: PrivateKey) -> AccountId:
7167
"""Create an account whose alias is derived from the provided ECDSA key."""
7268
print("\nSTEP 2: Creating the account using the fallback alias behaviour...")
69+
7370
transaction = AccountCreateTransaction(
7471
initial_balance=Hbar(5),
7572
memo="Account with alias derived from main ECDSA key",
@@ -81,40 +78,38 @@ def create_account_with_fallback_alias(
8178
new_account_id = response.account_id
8279

8380
if new_account_id is None:
84-
raise RuntimeError(
85-
"AccountID not found in receipt. Account may not have been created."
86-
)
81+
raise RuntimeError("AccountID not found in receipt. Account may not have been created.")
8782

8883
print(f"✅ Account created with ID: {new_account_id}\n")
84+
8985
return new_account_id
9086

9187

92-
def fetch_account_info(client: Client, account_id: AccountId):
88+
def fetch_account_info(client: Client, account_id: AccountId) -> AccountInfo:
9389
"""Fetch account info for the given account ID."""
9490
print("\nSTEP 3: Fetching account information...")
91+
9592
return AccountInfoQuery().set_account_id(account_id).execute(client)
9693

9794

98-
def print_account_summary(account_info) -> None:
95+
def print_account_summary(account_info: AccountInfo) -> None:
9996
"""Print an account summary (including EVM alias)."""
10097
print("\nSTEP 4: Printing account EVM alias and summary...")
101-
out = info_to_dict(account_info)
102-
print("Account Info:")
103-
print(json.dumps(out, indent=2) + "\n")
104-
print(
105-
"✅ contract_account_id (EVM alias on-chain): "
106-
f"{account_info.contract_account_id}"
107-
)
98+
print("🧾 Account Info:")
99+
print(account_info)
100+
print("")
101+
print(f"✅ contract_account_id (EVM alias on-chain): {account_info.contract_account_id}")
108102

109103

110104
def main():
111-
"""Main entry point."""
105+
"""Execute the example workflow."""
112106
client = setup_client()
113107
try:
114108
account_private_key = generate_fallback_key()
115109
new_account_id = create_account_with_fallback_alias(client, account_private_key)
116110
account_info = fetch_account_info(client, new_account_id)
117111
print_account_summary(account_info)
112+
118113
except Exception as error:
119114
print(f"❌ Error: {error}")
120115
sys.exit(1)
Lines changed: 49 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,52 @@
1-
"""
2-
Example: Create an account without using any alias.
1+
"""Example: Create an account without using any alias.
32
43
This demonstrates:
54
- Using `set_key_without_alias` so that no EVM alias is set
65
- The resulting `contract_account_id` being the zero-padded value
76
87
Usage:
9-
- uv run python examples/account/account_create_transaction_without_alias.py
10-
- python examples/account/account_create_transaction_without_alias.py
8+
uv run examples/account/account_create_transaction_without_alias.py
9+
python examples/account/account_create_transaction_without_alias.py
1110
"""
1211

13-
from typing import Tuple
12+
import os
1413
import sys
14+
from typing import Tuple
15+
16+
from dotenv import load_dotenv
1517

1618
from hiero_sdk_python import (
17-
Client,
18-
PrivateKey,
19-
PublicKey,
2019
AccountCreateTransaction,
21-
AccountInfoQuery,
2220
AccountId,
2321
AccountInfo,
22+
AccountInfoQuery,
23+
Client,
2424
Hbar,
25-
ResponseCode,
25+
Network,
26+
PrivateKey,
27+
PublicKey,
2628
)
2729

30+
load_dotenv()
31+
network_name = os.getenv("NETWORK", "testnet").lower()
32+
33+
2834
def setup_client() -> Client:
29-
"""Setup Client."""
30-
client = Client.from_env()
31-
print(f"Network: {client.network.network}")
32-
print(f"Client set up with operator id {client.operator_account_id}")
33-
return client
35+
"""Set up the Hedera client."""
36+
network = Network(network_name)
37+
print(f"Connecting to Hedera {network_name} network!")
38+
client = Client(network)
39+
40+
try:
41+
operator_id = AccountId.from_string(os.getenv("OPERATOR_ID", ""))
42+
operator_key = PrivateKey.from_string(os.getenv("OPERATOR_KEY", ""))
43+
client.set_operator(operator_id, operator_key)
44+
print(f"Client set up with operator id {client.operator_account_id}")
45+
return client
46+
except Exception:
47+
print("Error: Please check OPERATOR_ID and OPERATOR_KEY in your .env file.")
48+
sys.exit(1)
49+
3450

3551
def generate_account_key() -> Tuple[PrivateKey, PublicKey]:
3652
"""Generate a key pair for the account."""
@@ -40,10 +56,13 @@ def generate_account_key() -> Tuple[PrivateKey, PublicKey]:
4056
print(f"✅ Account public key (no alias): {account_public_key}")
4157
return account_private_key, account_public_key
4258

43-
def create_account_without_alias(client: Client, account_public_key: PublicKey, account_private_key: PrivateKey) -> AccountId:
59+
60+
def create_account_without_alias(
61+
client: Client, account_public_key: PublicKey, account_private_key: PrivateKey
62+
) -> AccountId:
4463
"""Create an account without setting any alias."""
4564
print("\nSTEP 2: Creating the account without setting any alias...")
46-
65+
4766
transaction = (
4867
AccountCreateTransaction(
4968
initial_balance=Hbar(5),
@@ -55,47 +74,39 @@ def create_account_without_alias(client: Client, account_public_key: PublicKey,
5574
)
5675

5776
response = transaction.execute(client)
58-
59-
if response.status != ResponseCode.SUCCESS:
60-
raise RuntimeError(
61-
f"Transaction failed with status: {response.status.name}"
62-
)
63-
6477
new_account_id = response.account_id
6578

6679
if new_account_id is None:
67-
raise RuntimeError(
68-
"AccountID not found in receipt. Account may not have been created."
69-
)
80+
raise RuntimeError("AccountID not found in receipt. Account may not have been created.")
7081

7182
print(f"✅ Account created with ID: {new_account_id}\n")
7283
return new_account_id
7384

85+
7486
def fetch_account_info(client: Client, account_id: AccountId) -> AccountInfo:
7587
"""Fetch account information."""
76-
account_info = (
77-
AccountInfoQuery()
78-
.set_account_id(account_id)
79-
.execute(client)
80-
)
81-
return account_info
88+
print("\nSTEP 3: Fetching account information...")
89+
return AccountInfoQuery().set_account_id(account_id).execute(client)
90+
8291

8392
def main() -> None:
84-
"""Main entry point."""
93+
"""Execute the example workflow."""
8594
try:
8695
client = setup_client()
8796
account_private_key, account_public_key = generate_account_key()
97+
8898
new_account_id = create_account_without_alias(client, account_public_key, account_private_key)
99+
89100
account_info = fetch_account_info(client, new_account_id)
90-
print("\nAccount Info:")
101+
102+
print("\n🧾 Account Info:")
91103
print(account_info)
92-
print(
93-
"\n✅ contract_account_id (no alias, zero-padded): "
94-
f"{account_info.contract_account_id}"
95-
)
104+
print(f"\n✅ contract_account_id (no alias, zero-padded): {account_info.contract_account_id}")
105+
96106
except Exception as error:
97107
print(f"❌ Error: {error}")
98108
sys.exit(1)
99109

110+
100111
if __name__ == "__main__":
101112
main()

0 commit comments

Comments
 (0)