1+ """
2+ Account Creation Example.
13
4+ This module demonstrates how to create a new Hedera account using the Hiero Python SDK.
5+ It shows the complete workflow from setting up a client with operator credentials
6+ to creating a new account and handling the transaction response.
27
8+ The example creates an account with:
9+ - A generated Ed25519 key pair
10+ - An initial balance of 1 HBAR (100,000,000 tinybars)
11+ - A custom account memo
12+
13+ Usage:
14+ Run this script directly:
15+ python examples/account/account_create_transaction.py
16+
17+ Or using uv:
18+ uv run examples/account/account_create_transaction.py
19+
20+ Requirements:
21+ - Environment variables OPERATOR_ID and OPERATOR_KEY must be set
22+ - A .env file with the operator credentials (recommended)
23+ - Sufficient HBAR balance in the operator account to pay for account creation
24+
25+ Environment Variables:
26+ OPERATOR_ID (str): The account ID of the operator (format: "0.0.xxxxx")
27+ OPERATOR_KEY (str): The private key of the operator account
28+ NETWORK (str, optional): Network to use (default: "testnet")
29+ """
330import sys
431from hiero_sdk_python import (
532 Client ,
835 ResponseCode ,
936)
1037
11-
1238def create_new_account (client : Client ) -> None :
13-
39+ """
40+ Create a new Hedera account with generated keys and initial balance.
41+
42+ This function generates a new Ed25519 key pair, creates an account creation
43+ transaction, signs it with the operator key, and executes it on the network.
44+ The new account is created with an initial balance and a custom memo.
45+
46+ Args:
47+ client (Client): Configured Hedera client instance with operator set
48+
49+ Returns:
50+ None: This function doesn't return a value but prints the results
51+
52+ Raises:
53+ Exception: If the transaction fails or the account ID is not found in the receipt
54+ SystemExit: Calls sys.exit(1) if account creation fails
55+
56+ Side Effects:
57+ - Prints transaction status and account details to stdout
58+ - Creates a new account on the Hedera network
59+ - Deducts transaction fees from the operator account
60+ - Exits the program with code 1 if creation fails
61+
62+ Example Output:
63+ Transaction status: ResponseCode.SUCCESS
64+ Account creation successful. New Account ID: 0.0.123456
65+ New Account Private Key: 302e020100300506032b657004220420...
66+ New Account Public Key: 302a300506032b6570032100...
67+ """
1468 new_account_private_key = PrivateKey .generate ("ed25519" )
1569 new_account_public_key = new_account_private_key .public_key ()
1670
@@ -39,17 +93,14 @@ def create_new_account(client: Client) -> None:
3993 print (f" New Account Private Key: { new_account_private_key .to_string ()} " )
4094 print (f" New Account Public Key: { new_account_public_key .to_string ()} " )
4195 else :
42- raise Exception (
43- "AccountID not found in receipt. Account may not have been created."
44- )
96+ raise Exception ("AccountID not found in receipt. Account may not have been created." )
4597
4698 except Exception as e :
4799 print (f"❌ Account creation failed: { str (e )} " )
48100 sys .exit (1 )
49101
50-
51- if __name__ == "__main__" :
102+ if __name__ == "__main__" :
52103 client = Client .from_env ()
53104 print (f"Operator: { client .operator_account_id } " )
54105 create_new_account (client )
55- client .close ()
106+ client .close ()
0 commit comments