88from multiversx_sdk import (
99 Account ,
1010 Address ,
11+ ApiNetworkProvider ,
1112 LedgerAccount ,
1213 ProxyNetworkProvider ,
1314 Transaction ,
@@ -103,13 +104,13 @@ def add_tx_args(
103104 type = int ,
104105 required = False ,
105106 default = None ,
106- help = "# the nonce for the transaction" ,
107+ help = "# the nonce for the transaction. If not provided, is fetched from the network. " ,
107108 )
108109 sub .add_argument (
109110 "--recall-nonce" ,
110111 action = "store_true" ,
111112 default = False ,
112- help = "⭮ whether to recall the nonce when creating the transaction (default: %(default)s)" ,
113+ help = "⭮ whether to recall the nonce when creating the transaction (default: %(default)s). This argument is OBSOLETE. " ,
113114 )
114115
115116 if with_receiver :
@@ -175,6 +176,9 @@ def add_wallet_args(args: list[str], sub: Any):
175176 help = "🔑 the address index; can be used for PEM files, keyfiles of type mnemonic or Ledger devices (default: %(default)s)" ,
176177 )
177178 sub .add_argument ("--sender-username" , required = False , help = "🖄 the username of the sender" )
179+ sub .add_argument (
180+ "--hrp" , required = False , type = str , help = "The hrp used to convert the address to its bech32 representation"
181+ )
178182
179183
180184def add_guardian_wallet_args (args : list [str ], sub : Any ):
@@ -282,7 +286,7 @@ def parse_omit_fields_arg(args: Any) -> list[str]:
282286
283287
284288def prepare_account (args : Any ):
285- hrp = config . get_address_hrp ( )
289+ hrp = _get_address_hrp ( args )
286290
287291 if args .pem :
288292 return Account .new_from_pem (file_path = Path (args .pem ), index = args .sender_wallet_index , hrp = hrp )
@@ -302,8 +306,43 @@ def prepare_account(args: Any):
302306 raise errors .NoWalletProvided ()
303307
304308
309+ def _get_address_hrp (args : Any ) -> str :
310+ """Use hrp provided by the user. If not provided, fetch from network. If proxy not provided, get hrp from config."""
311+ hrp : str = ""
312+
313+ if hasattr (args , "hrp" ) and args .hrp :
314+ hrp = args .hrp
315+ return hrp
316+
317+ if hasattr (args , "proxy" ) and args .proxy :
318+ hrp = _get_hrp_from_proxy (args )
319+ elif hasattr (args , "api" ) and args .api :
320+ hrp = _get_hrp_from_api (args )
321+
322+ if hrp :
323+ return hrp
324+
325+ return config .get_address_hrp ()
326+
327+
328+ def _get_hrp_from_proxy (args : Any ) -> str :
329+ network_provider_config = config .get_config_for_network_providers ()
330+ proxy = ProxyNetworkProvider (url = args .proxy , config = network_provider_config )
331+ network_config = proxy .get_network_config ()
332+ hrp : str = network_config .raw .get ("erd_address_hrp" , "" )
333+ return hrp
334+
335+
336+ def _get_hrp_from_api (args : Any ) -> str :
337+ network_provider_config = config .get_config_for_network_providers ()
338+ proxy = ApiNetworkProvider (url = args .api , config = network_provider_config )
339+ network_config = proxy .get_network_config ()
340+ hrp : str = network_config .raw .get ("erd_address_hrp" , "" )
341+ return hrp
342+
343+
305344def load_guardian_account (args : Any ) -> Union [IAccount , None ]:
306- hrp = config . get_address_hrp ( )
345+ hrp = _get_address_hrp ( args )
307346
308347 if args .guardian_pem :
309348 return Account .new_from_pem (file_path = Path (args .guardian_pem ), index = args .guardian_wallet_index , hrp = hrp )
@@ -434,7 +473,7 @@ def _is_matching_address(account_address: Union[Address, None], args_address: Un
434473
435474
436475def load_relayer_account (args : Any ) -> Union [IAccount , None ]:
437- hrp = config . get_address_hrp ( )
476+ hrp = _get_address_hrp ( args )
438477
439478 if args .relayer_pem :
440479 return Account .new_from_pem (file_path = Path (args .relayer_pem ), index = args .relayer_wallet_index , hrp = hrp )
0 commit comments