For the complete documentation index, see llms.txt. This page is also available as Markdown.

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());

WalletService does not save the mnemonic nor the private key. If you generate a new mnemonic make sure to save it!

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:

Synchronizing is very important to view what your wallet has. There are some related functionalities with synchronizing such as saving the wallet state and having callbacks each time a wallet synchronizes.

Importing and creating multiple wallets

To create multiple testnet or mainnet wallets you just need one ConnectionService for each network. For example:

Last updated