77
88from aleph .sdk .chains .common import get_fallback_private_key
99from aleph .sdk .chains .ethereum import ETHAccount
10+ from aleph .sdk .chains .evm import EVMAccount
1011from aleph .sdk .chains .remote import RemoteAccount
1112from aleph .sdk .chains .solana import SOLAccount
13+ from aleph .sdk .chains .substrate import DOTAccount
1214from aleph .sdk .conf import load_main_configuration , settings
1315from aleph .sdk .evm_utils import get_chains_with_super_token
1416from aleph .sdk .types import AccountFromPrivateKey
1820T = TypeVar ("T" , bound = AccountFromPrivateKey )
1921
2022chain_account_map : Dict [Chain , Type [T ]] = { # type: ignore
21- Chain .ETH : ETHAccount ,
23+ Chain .ARBITRUM : EVMAccount ,
2224 Chain .AVAX : ETHAccount ,
2325 Chain .BASE : ETHAccount ,
26+ Chain .BLAST : EVMAccount ,
27+ Chain .BOB : EVMAccount ,
28+ Chain .CYBER : EVMAccount ,
29+ Chain .DOT : DOTAccount ,
30+ Chain .ETH : ETHAccount ,
31+ Chain .FRAXTAL : EVMAccount ,
32+ Chain .LINEA : EVMAccount ,
33+ Chain .LISK : EVMAccount ,
34+ Chain .METIS : EVMAccount ,
35+ Chain .MODE : EVMAccount ,
36+ Chain .OPTIMISM : EVMAccount ,
37+ Chain .POL : EVMAccount ,
2438 Chain .SOL : SOLAccount ,
39+ Chain .WORLDCHAIN : EVMAccount ,
40+ Chain .ZORA : EVMAccount ,
2541}
2642
2743
@@ -43,7 +59,7 @@ def account_from_hex_string(
4359 return account_type (bytes .fromhex (private_key_str )) # type: ignore
4460
4561 account_type = load_chain_account_type (chain )
46- account = account_type (bytes .fromhex (private_key_str ))
62+ account = account_type (bytes .fromhex (private_key_str ), chain )
4763 if chain in get_chains_with_super_token ():
4864 account .switch_chain (chain )
4965 return account # type: ignore
@@ -62,7 +78,7 @@ def account_from_file(
6278 return account_type (private_key ) # type: ignore
6379
6480 account_type = load_chain_account_type (chain )
65- account = account_type (private_key )
81+ account = account_type (private_key , chain )
6682 if chain in get_chains_with_super_token ():
6783 account .switch_chain (chain )
6884 return account
@@ -76,28 +92,29 @@ def _load_account(
7692) -> AccountFromPrivateKey :
7793 """Load an account from a private key string or file, or from the configuration file."""
7894
79- # Loads configuration if no account_type is specified
80- if not account_type :
81- config = load_main_configuration (settings .CONFIG_FILE )
95+ config = load_main_configuration (settings .CONFIG_FILE )
96+ chain_to_use = settings .DEFAULT_CHAIN
97+
98+ if not chain :
8299 if config and hasattr (config , "chain" ):
83- account_type = load_chain_account_type ( config .chain )
100+ chain_to_use = config .chain
84101 logger .debug (
85102 f"Detected { config .chain } account for path { settings .CONFIG_FILE } "
86103 )
87- else :
88- account_type = account_type = load_chain_account_type (
89- Chain . ETH
90- ) # Defaults to ETHAccount
91- logger .warning (
92- f"No main configuration data found in { settings .CONFIG_FILE } , defaulting to { account_type and account_type .__name__ } "
93- )
104+
105+ # Loads configuration if no account_type is specified
106+ if not account_type :
107+ account_type = load_chain_account_type ( chain_to_use )
108+ logger .warning (
109+ f"No main configuration data found in { settings .CONFIG_FILE } , defaulting to { account_type and account_type .__name__ } "
110+ )
94111
95112 # Loads private key from a string
96113 if private_key_str :
97- return account_from_hex_string (private_key_str , account_type , chain )
114+ return account_from_hex_string (private_key_str , account_type , chain_to_use )
98115 # Loads private key from a file
99116 elif private_key_path and private_key_path .is_file ():
100- return account_from_file (private_key_path , account_type , chain )
117+ return account_from_file (private_key_path , account_type , chain_to_use )
101118 # For ledger keys
102119 elif settings .REMOTE_CRYPTO_HOST :
103120 logger .debug ("Using remote account" )
@@ -112,7 +129,7 @@ def _load_account(
112129 else :
113130 new_private_key = get_fallback_private_key ()
114131 account = account_from_hex_string (
115- bytes .hex (new_private_key ), account_type , chain
132+ bytes .hex (new_private_key ), account_type , chain_to_use
116133 )
117134 logger .info (
118135 f"Generated fallback private key with address { account .get_address ()} "
0 commit comments