Wallet loader
In this section we will make a wallet loader that uses a storage service. The storage service will be used to save and load the wallet state.
We will show two different ways to achieve this.
Calling getWalletService
import { WalletService, Environments } from "@peersyst/ckb-wallet-sdk";
import { mainnetConnection, testnetConnection } from "./network-connections";
import { saveWalletState, loadWalletInfo } from "./storage-service";
export function loadWallet(walletId: number): WalletService {
const { mnemonic, walletState, environment } = loadWalletInfo(walletId);
if (environment === Environments.Mainnet) {
const wallet = new WalletService(mainnetConnection, mnemonic, walletState);
return wallet;
}
const wallet = new WalletService(testnetConnection, mnemonic, walletState);
return wallet;
}
export function saveWallet(walletId: number, wallet: WalletService): void {
const walletState = wallet.getWalletState();
saveWalletState(walletId, walletState);
}With onSync
Last updated