From 341820666af4e03648f4c5642b77bfe5a8d45988 Mon Sep 17 00:00:00 2001 From: MonaaEid Date: Fri, 28 Nov 2025 22:48:55 +0200 Subject: [PATCH 1/6] feat: implement account creation with EVM-style alias transaction example Signed-off-by: MonaaEid --- CHANGELOG.md | 2 +- .../create_account_with_alias_transaction.py | 111 ++++++++++++++++++ 2 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 examples/account/create_account_with_alias_transaction.py diff --git a/CHANGELOG.md b/CHANGELOG.md index db344d25c..da4db7cbf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1. - Add example demonstrating usage of `CustomFeeLimit` in `examples/transaction/custom_fee_limit.py` - Added `.github/workflows/merge-conflict-bot.yml` to automatically detect and notify users of merge conflicts in Pull Requests. - Added `.github/workflows/bot-office-hours.yml` to automate the Weekly Office Hour Reminder. - +- feat: Implement account creation with EVM-style alias transaction example. ### Changed - Removed duplicate import of transaction_pb2 in transaction.py diff --git a/examples/account/create_account_with_alias_transaction.py b/examples/account/create_account_with_alias_transaction.py new file mode 100644 index 000000000..3de46b01e --- /dev/null +++ b/examples/account/create_account_with_alias_transaction.py @@ -0,0 +1,111 @@ +# uv run examples/account/create_account_with_alias_transaction.py +# python examples/account/create_account_with_alias_transaction.py +""" +Example: Create an account using an EVM-style alias (evm_address). +""" + +import os +import sys +import json +from dotenv import load_dotenv + +from hiero_sdk_python import ( + Client, + PrivateKey, + AccountCreateTransaction, + AccountInfoQuery, + Network, + AccountId, + Hbar, +) + +load_dotenv() +network_name = os.getenv('NETWORK', 'testnet').lower() +key_type = os.getenv('KEY_TYPE', 'ecdsa') + +def setup_client(): + """Setup Client """ + network = Network(network_name) + print(f"Connecting to Hedera {network_name} network!") + client = Client(network) + + # Get the operator account from the .env file + try: + operator_id = AccountId.from_string(os.getenv('OPERATOR_ID', '')) + operator_key = PrivateKey.from_string(os.getenv('OPERATOR_KEY', '')) + # Set the operator (payer) account for the client + client.set_operator(operator_id, operator_key) + print(f"Client set up with operator id {client.operator_account_id}") + return client + except Exception: + print("Error: Please check OPERATOR_ID and OPERATOR_KEY in your .env file.") + sys.exit(1) + +def info_to_dict(info): + """Convert AccountInfo to dictionary for easy printing.""" + out = {} + for name in dir(info): + if name.startswith("_"): + continue + try: + val = getattr(info, name) + except Exception as error: + out[name] = f"Error retrieving value: {error}" + continue + if callable(val): + continue + out[name] = str(val) + return out + +def create_account_with_alias(client): + """Create an account with an alias transaction.""" + try: + print("\nSTEP 1: Generating a new ECDSA key pair for the account alias...") + private_key = PrivateKey.generate("ecdsa") + public_key = private_key.public_key() + evm_address = public_key.to_evm_address() + if evm_address is None: + print("โŒ Error generating ECDSA key pair") + sys.exit(1) + print(f"โœ… Generated new ECDSA key pair. EVM Address (alias): {evm_address}") + # Create the account with the alias + print("\nSTEP 2: Creating the account with the EVM address alias...") + transaction = ( + AccountCreateTransaction() + .set_key(public_key) + .set_initial_balance(Hbar(5)) + .set_alias(evm_address) + ) + + # Sign the transaction with both the new key and the operator key + transaction = transaction.freeze_with(client) \ + .sign(private_key) \ + .sign(client.operator_private_key) + + # Execute the transaction + response = transaction.execute(client) + new_account_id = response.account_id + print(f"โœ… Account created with ID: {new_account_id}\n") + # Fetch and display account info + account_info = AccountInfoQuery().set_account_id(new_account_id).execute(client) + # Print the account info + out = info_to_dict(account_info) + print("๐Ÿงพ Account Info:") + print(json.dumps(out, indent=2) + "\n") + if account_info.contract_account_id is not None: + print(f"โœ… Contract Account ID (alias): {account_info.contract_account_id}") + else: + print("โŒ Error: Contract Account ID (alias) does not exist.") + + except Exception as error: + print(f"โŒ Error: {error}") + sys.exit(1) + +def main(): + """Main function to create an account with an alias transaction.""" + client = setup_client() + create_account_with_alias(client) + + +if __name__ == "__main__": + main() From d08f2b4aeddca4431e78fe2a594c07f419aa3fcd Mon Sep 17 00:00:00 2001 From: MontyPokemon <59332150+MonaaEid@users.noreply.github.com> Date: Sat, 29 Nov 2025 00:06:18 +0200 Subject: [PATCH 2/6] feat: implement account creation with EVM-style alias transaction example Signed-off-by: MontyPokemon <59332150+MonaaEid@users.noreply.github.com> --- .../account/create_account_with_alias_transaction.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/examples/account/create_account_with_alias_transaction.py b/examples/account/create_account_with_alias_transaction.py index 3de46b01e..b0241ef7f 100644 --- a/examples/account/create_account_with_alias_transaction.py +++ b/examples/account/create_account_with_alias_transaction.py @@ -61,7 +61,7 @@ def create_account_with_alias(client): """Create an account with an alias transaction.""" try: print("\nSTEP 1: Generating a new ECDSA key pair for the account alias...") - private_key = PrivateKey.generate("ecdsa") + private_key = PrivateKey.generate(key_type) public_key = private_key.public_key() evm_address = public_key.to_evm_address() if evm_address is None: @@ -102,7 +102,12 @@ def create_account_with_alias(client): sys.exit(1) def main(): - """Main function to create an account with an alias transaction.""" + """Main function to create an account with an alias transaction. + 1- Setup client + 2- Generate ECDSA key pair and EVM address alias + 3- Create account with alias + 4- Print account info + """ client = setup_client() create_account_with_alias(client) From 90248d9b86452aaee782ad8d4ea67ec9e00d9ce7 Mon Sep 17 00:00:00 2001 From: MontyPokemon <59332150+MonaaEid@users.noreply.github.com> Date: Sat, 29 Nov 2025 01:16:34 +0200 Subject: [PATCH 3/6] feat: implement account creation with EVM-style alias transaction example Signed-off-by: MontyPokemon <59332150+MonaaEid@users.noreply.github.com> --- examples/account/create_account_with_alias_transaction.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/account/create_account_with_alias_transaction.py b/examples/account/create_account_with_alias_transaction.py index b0241ef7f..f05beadab 100644 --- a/examples/account/create_account_with_alias_transaction.py +++ b/examples/account/create_account_with_alias_transaction.py @@ -65,13 +65,14 @@ def create_account_with_alias(client): public_key = private_key.public_key() evm_address = public_key.to_evm_address() if evm_address is None: - print("โŒ Error generating ECDSA key pair") + print("โŒ Error: Failed to generate EVM address from public key.") sys.exit(1) print(f"โœ… Generated new ECDSA key pair. EVM Address (alias): {evm_address}") # Create the account with the alias print("\nSTEP 2: Creating the account with the EVM address alias...") transaction = ( AccountCreateTransaction() + .set_key(public_key) .set_initial_balance(Hbar(5)) .set_alias(evm_address) From 5152e6e641748f37056d19b8de261146e03667c0 Mon Sep 17 00:00:00 2001 From: MonaaEid Date: Sat, 29 Nov 2025 01:45:40 +0200 Subject: [PATCH 4/6] feat: implement account creation with EVM-style alias transaction example Signed-off-by: MonaaEid --- examples/account/create_account_with_alias_transaction.py | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/account/create_account_with_alias_transaction.py b/examples/account/create_account_with_alias_transaction.py index f05beadab..ad1cfc1d5 100644 --- a/examples/account/create_account_with_alias_transaction.py +++ b/examples/account/create_account_with_alias_transaction.py @@ -72,7 +72,6 @@ def create_account_with_alias(client): print("\nSTEP 2: Creating the account with the EVM address alias...") transaction = ( AccountCreateTransaction() - .set_key(public_key) .set_initial_balance(Hbar(5)) .set_alias(evm_address) From c8ac3aa8aab9fbabfc14091244a291ee49406dad Mon Sep 17 00:00:00 2001 From: MontyPokemon <59332150+MonaaEid@users.noreply.github.com> Date: Sat, 29 Nov 2025 14:19:52 +0200 Subject: [PATCH 5/6] feat: implement account creation with EVM-style alias transaction example Signed-off-by: MontyPokemon <59332150+MonaaEid@users.noreply.github.com> --- ...ias_transaction.py => account_create_transaction_evm_alias.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename examples/account/{create_account_with_alias_transaction.py => account_create_transaction_evm_alias.py} (100%) diff --git a/examples/account/create_account_with_alias_transaction.py b/examples/account/account_create_transaction_evm_alias.py similarity index 100% rename from examples/account/create_account_with_alias_transaction.py rename to examples/account/account_create_transaction_evm_alias.py From c10d99d1b50aed457c15750891568e2db0f87f2a Mon Sep 17 00:00:00 2001 From: MontyPokemon <59332150+MonaaEid@users.noreply.github.com> Date: Mon, 1 Dec 2025 16:37:59 +0200 Subject: [PATCH 6/6] feat: implement account creation with EVM-style alias transaction example Signed-off-by: MontyPokemon <59332150+MonaaEid@users.noreply.github.com> --- examples/account/account_create_transaction_evm_alias.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/examples/account/account_create_transaction_evm_alias.py b/examples/account/account_create_transaction_evm_alias.py index ad1cfc1d5..2b8a4eab6 100644 --- a/examples/account/account_create_transaction_evm_alias.py +++ b/examples/account/account_create_transaction_evm_alias.py @@ -1,5 +1,5 @@ -# uv run examples/account/create_account_with_alias_transaction.py -# python examples/account/create_account_with_alias_transaction.py +# uv run examples/account/account_create_transaction_evm_alias.py +# python examples/account/account_create_transaction_evm_alias.py """ Example: Create an account using an EVM-style alias (evm_address). """ @@ -21,7 +21,6 @@ load_dotenv() network_name = os.getenv('NETWORK', 'testnet').lower() -key_type = os.getenv('KEY_TYPE', 'ecdsa') def setup_client(): """Setup Client """ @@ -61,7 +60,7 @@ def create_account_with_alias(client): """Create an account with an alias transaction.""" try: print("\nSTEP 1: Generating a new ECDSA key pair for the account alias...") - private_key = PrivateKey.generate(key_type) + private_key = PrivateKey.generate('ecdsa') public_key = private_key.public_key() evm_address = public_key.to_evm_address() if evm_address is None: