Instantiate your wallet service
Once we have instantiated the connection service the next step is to instantiate a WalletService for each wallet in each network we want to work with.
To create the service you need a mnemonic. This mnemonic can be generated or imported.
Create new wallet with a generated mnemonic
If, for example, you would want to create a mnemonic on mainnet you could do:
import { ConnectionService, Environments, Logger, WalletService } from "@peersyst/ckb-wallet-sdk";
const rpcUrl = "http://localhost:8117/rpc";
const indexerUrl = "http://localhost:8117/indexer";
const mainnetConnectionService = new ConnectionService(rpcUrl, indexerUrl, Environments.Mainnet);
const myMnemonic = WalletService.createNewMnemonic();
Logger.info(myMnemonic);
const myWallet = new WalletService(mainnetConnectionService, myMnemonic);
Logger.info(myWallet.getNextAddress());At this point you can already use myWallet to get your address, send transactions or view your balance (which will be 0 as it is a newly created wallet!).
Import a wallet from an existing mnemonic
If you already have your mnemonic you will not need to generate a new one. You can import the wallet as follows:
Importing and creating multiple wallets
To create multiple testnet or mainnet wallets you just need one ConnectionService for each network. For example:
Last updated