2828from cdp .faucet_transaction import FaucetTransaction
2929from cdp .trade import Trade
3030from cdp .wallet_address import WalletAddress
31+ from cdp .wallet_data import WalletData
3132
3233
3334class Wallet :
@@ -176,8 +177,8 @@ def reload(self) -> None:
176177 self ._model = model
177178 return
178179
179- @staticmethod
180- def fetch (wallet_id : str ) -> "Wallet" :
180+ @classmethod
181+ def fetch (cls , wallet_id : str ) -> "Wallet" :
181182 """Fetch a wallet by its ID.
182183
183184 Args:
@@ -192,7 +193,7 @@ def fetch(wallet_id: str) -> "Wallet":
192193 """
193194 model = Cdp .api_clients .wallets .get_wallet (wallet_id )
194195
195- return Wallet (model , "" )
196+ return cls (model , "" )
196197
197198 @classmethod
198199 def list (cls ) -> Iterator ["Wallet" ]:
@@ -218,6 +219,31 @@ def list(cls) -> Iterator["Wallet"]:
218219
219220 page = response .next_page
220221
222+ @classmethod
223+ def import_data (cls , data : WalletData ) -> "Wallet" :
224+ """Import a wallet from previously exported wallet data.
225+
226+ Args:
227+ data (WalletData): The wallet data to import.
228+
229+ Returns:
230+ Wallet: The imported wallet.
231+
232+ Raises:
233+ Exception: If there's an error getting the wallet.
234+
235+ """
236+ if not isinstance (data , WalletData ):
237+ raise ValueError ("Data must be a WalletData instance" )
238+
239+ model = Cdp .api_clients .wallets .get_wallet (data .wallet_id )
240+
241+ wallet = cls (model , data .seed )
242+
243+ wallet ._set_addresses ()
244+
245+ return wallet
246+
221247 def create_address (self ) -> "WalletAddress" :
222248 """Create a new address for the wallet.
223249
@@ -372,6 +398,21 @@ def default_address(self) -> WalletAddress | None:
372398 else None
373399 )
374400
401+ def export_data (self ) -> WalletData :
402+ """Export the wallet's data.
403+
404+ Returns:
405+ WalletData: The wallet's data.
406+
407+ Raises:
408+ ValueError: If the wallet does not have a seed loaded.
409+
410+ """
411+ if self ._master is None or self ._seed is None :
412+ raise ValueError ("Wallet does not have seed loaded" )
413+
414+ return WalletData (self .id , self ._seed )
415+
375416 def save_seed (self , file_path : str , encrypt : bool | None = False ) -> None :
376417 """Save the wallet seed to a file.
377418
0 commit comments