33"""
44
55from typing import Optional , Union
6+ import warnings
67
8+ from hiero_sdk_python .account .account_id import AccountId
79from hiero_sdk_python .channels import _Channel
10+ from hiero_sdk_python .crypto .evm_address import EvmAddress
811from hiero_sdk_python .crypto .public_key import PublicKey
912from hiero_sdk_python .Duration import Duration
1013from hiero_sdk_python .executable import _Method
@@ -31,7 +34,11 @@ def __init__(
3134 receiver_signature_required : Optional [bool ] = None ,
3235 auto_renew_period : Optional [Duration ] = AUTO_RENEW_PERIOD ,
3336 memo : Optional [str ] = None ,
34- max_automatic_token_associations : Optional [int ] = 0
37+ max_automatic_token_associations : Optional [int ] = 0 ,
38+ alias : Optional [EvmAddress ] = None ,
39+ staked_account_id : Optional [AccountId ] = None ,
40+ staked_node_id : Optional [int ] = None ,
41+ decline_staking_reward : Optional [bool ] = False
3542 ) -> None :
3643 """
3744 Initializes a new AccountCreateTransaction instance with default values
@@ -43,6 +50,13 @@ def __init__(
4350 receiver_signature_required (Optional[bool]): Whether receiver signature is required.
4451 auto_renew_period (Duration): Auto-renew period in seconds (default is ~90 days).
4552 memo (Optional[str]): Memo for the account.
53+ max_automatic_token_associations (Optional[int]): The maximum number of tokens that
54+ can be auto-associated.
55+ alias (Optional[EvmAddress]): The 20-byte EVM address to be used as the account's alias.
56+ staked_account_id (Optional[AccountId]): The account to which this account will stake.
57+ staked_node_id (Optional[int]): ID of the node this account is staked to.
58+ decline_staking_reward (Optional[bool]): If true, the account declines receiving a
59+ staking reward (default is False).
4660 """
4761 super ().__init__ ()
4862 self .key : Optional [PublicKey ] = key
@@ -52,6 +66,10 @@ def __init__(
5266 self .account_memo : Optional [str ] = memo
5367 self .max_automatic_token_associations : Optional [int ] = max_automatic_token_associations
5468 self ._default_transaction_fee = DEFAULT_TRANSACTION_FEE
69+ self .alias : Optional [EvmAddress ] = alias
70+ self .staked_account_id : Optional [AccountId ] = staked_account_id
71+ self .staked_node_id : Optional [int ] = staked_node_id
72+ self .decline_staking_reward = decline_staking_reward
5573
5674 def set_key (self , key : PublicKey ) -> "AccountCreateTransaction" :
5775 """
@@ -63,8 +81,50 @@ def set_key(self, key: PublicKey) -> "AccountCreateTransaction":
6381 Returns:
6482 AccountCreateTransaction: The current transaction instance for method chaining.
6583 """
84+ warnings .warn (
85+ "The 'set_key' method is deprecated, Use `set_key_without_alias` instead." ,
86+ DeprecationWarning ,
87+ )
88+ self ._require_not_frozen ()
89+ self .key = key
90+ return self
91+
92+ def set_key_without_alias (self , key : PublicKey ) -> "AccountCreateTransaction" :
93+ """
94+ Sets the public key for the new account without alias.
95+
96+ Args:
97+ key (PublicKey): The public key to assign to the account.
98+
99+ Returns:
100+ AccountCreateTransaction: The current transaction instance for method chaining.
101+ """
102+ self ._require_not_frozen ()
103+ self .key = key
104+ return self
105+
106+ def set_key_with_alias (
107+ self ,
108+ key : PublicKey ,
109+ ecdsa_key : Optional [PublicKey ]= None
110+ ) -> "AccountCreateTransaction" :
111+ """
112+ Sets the public key for the new account and assigns an alias derived from an ECDSA key.
113+
114+ If `ecdsa_key` is provided, its corresponding EVM address will be used as the account alias.
115+ Otherwise, the alias will be derived from the provided `key`.
116+
117+ Args:
118+ key (PublicKey): The public key to assign to the account.
119+ ecdsa_key (Optional[PublicKey]): An optional ECDSA public key used
120+ to derive the account alias.
121+
122+ Returns:
123+ AccountCreateTransaction: The current transaction instance to allow method chaining.
124+ """
66125 self ._require_not_frozen ()
67126 self .key = key
127+ self .alias = ecdsa_key .to_evm_address () if ecdsa_key is not None else key .to_evm_address ()
68128 return self
69129
70130 def set_initial_balance (self , balance : Union [Hbar , int ]) -> "AccountCreateTransaction" :
@@ -133,15 +193,111 @@ def set_account_memo(self, memo: str) -> "AccountCreateTransaction":
133193 return self
134194
135195 def set_max_automatic_token_associations (self , max_assoc : int ) -> "AccountCreateTransaction" :
136- """Sets the maximum number of automatic token associations for the account."""
196+ """
197+ Sets the maximum number of automatic token associations for the account.
198+
199+ Args:
200+ max_assoc (int): The maximum number of automatic
201+ token associations to allow (default 0).
202+
203+ Returns:
204+ AccountCreateTransaction: The current transaction instance for method chaining.
205+ """
137206 self ._require_not_frozen ()
138207 # FIX
139208 if max_assoc < - 1 :
140209 raise ValueError ("max_automatic_token_associations must be -1 (unlimited) or a non-negative integer." )
141210 self .max_automatic_token_associations = max_assoc
142211 return self
143212
144- def _build_proto_body (self ):
213+ def set_alias (self , alias_evm_address : Union [EvmAddress , str ]) -> "AccountCreateTransaction" :
214+ """
215+ Sets the EVM Address alias for the account.
216+
217+ Args:
218+ alias_evm_address (Union[EvmAddress, str]): The 20-byte EVM address to
219+ be used as the account's alias.
220+
221+ Returns:
222+ AccountCreateTransaction: The current transaction instance for method chaining.
223+ """
224+ self ._require_not_frozen ()
225+ if isinstance (alias_evm_address , str ):
226+ if len (alias_evm_address .removeprefix ("0x" )) == 40 :
227+ self .alias = EvmAddress .from_string (alias_evm_address )
228+ else :
229+ raise ValueError ("alias_evm_address must be a valid 20-byte EVM address" )
230+
231+ elif isinstance (alias_evm_address , EvmAddress ):
232+ self .alias = alias_evm_address
233+
234+ else :
235+ raise TypeError ("alias_evm_address must be of type str or EvmAddress" )
236+
237+ return self
238+
239+ def set_staked_account_id (
240+ self ,
241+ account_id : Union [AccountId , str ]
242+ ) -> "AccountCreateTransaction" :
243+ """
244+ Sets the staked account id for the account.
245+
246+ Args:
247+ account_id (Union[AccountId, str]): The account to which this account will stake.
248+
249+ Returns:
250+ AccountCreateTransaction: The current transaction instance for method chaining.
251+ """
252+ self ._require_not_frozen ()
253+ if isinstance (account_id , str ):
254+ self .staked_account_id = AccountId .from_string (account_id )
255+ elif isinstance (account_id , AccountId ):
256+ self .staked_account_id = account_id
257+ else :
258+ raise TypeError ("account_id must be of type str or AccountId" )
259+
260+ return self
261+
262+ def set_staked_node_id (self , node_id : int ) -> "AccountCreateTransaction" :
263+ """
264+ Sets the staked node id for the account.
265+
266+ Args:
267+ node_id (int): The node to which this account will stake.
268+
269+ Returns:
270+ AccountCreateTransaction: The current transaction instance for method chaining.
271+ """
272+ self ._require_not_frozen ()
273+ if not isinstance (node_id , int ):
274+ raise TypeError ("node_id must be of type int" )
275+
276+ self .staked_node_id = node_id
277+ return self
278+
279+ def set_decline_staking_reward (
280+ self ,
281+ decline_staking_reward : bool
282+ ) -> "AccountCreateTransaction" :
283+ """
284+ Sets the decline staking reward for the account.
285+
286+ Args:
287+ decline_staking_reward (bool): If true, the account declines
288+ receiving a staking reward (default is False)
289+
290+ Returns:
291+ AccountCreateTransaction: The current transaction instance for method chaining.
292+ """
293+ self ._require_not_frozen ()
294+ if not isinstance (decline_staking_reward , bool ):
295+ raise TypeError ("decline_staking_reward must be of type bool" )
296+
297+ self .decline_staking_reward = decline_staking_reward
298+ return self
299+
300+ def _build_proto_body (self ) -> crypto_create_pb2 .CryptoCreateTransactionBody :
145301 """
146302 Returns the protobuf body for the account create transaction.
147303
@@ -162,15 +318,24 @@ def _build_proto_body(self):
162318 else :
163319 raise TypeError ("initial_balance must be Hbar or int (tinybars)." )
164320
165- return crypto_create_pb2 .CryptoCreateTransactionBody (
321+ proto_body = crypto_create_pb2 .CryptoCreateTransactionBody (
166322 key = self .key ._to_proto (),
167323 initialBalance = initial_balance_tinybars ,
168324 receiverSigRequired = self .receiver_signature_required ,
169325 autoRenewPeriod = duration_pb2 .Duration (seconds = self .auto_renew_period .seconds ),
170326 memo = self .account_memo ,
171- max_automatic_token_associations = self .max_automatic_token_associations
327+ max_automatic_token_associations = self .max_automatic_token_associations ,
328+ alias = self .alias .address_bytes if self .alias else None ,
329+ decline_reward = self .decline_staking_reward
172330 )
173331
332+ if self .staked_account_id :
333+ proto_body .staked_account_id .CopyFrom (self .staked_account_id ._to_proto ())
334+ elif self .staked_node_id :
335+ proto_body .staked_node_id = self .staked_node_id
336+
337+ return proto_body
338+
174339 def build_transaction_body (self ) -> transaction_pb2 .TransactionBody :
175340 """
176341 Builds and returns the protobuf transaction body for account creation.
0 commit comments