import { ConnectionService, Environments, WalletService, Logger } from"../src";constckbUrl="http://localhost:8117/rpc";constindexerUrl="http://localhost:8117/indexer";constmain=async () => {try {constmnemonic=WalletService.createNewMnemonic();Logger.info(mnemonic); // Your new generated mnemonic, save itconstconnectionService=newConnectionService(ckbUrl, indexerUrl,Environments.Testnet);constwallet=newWalletService(connectionService, mnemonic);// You can have more than 1 public address per mnemonicconstnextAddress=wallet.getNextAddress();Logger.info(nextAddress);// To get your private key you need to put you mnemonic as sdk does not keep itconst { privateKey,address } =wallet.getAddressAndPrivateKey(mnemonic);Logger.info(privateKey);Logger.info(address); } catch (error) {Logger.error(`${error.name}: ${error.message}`); }};main();
Get next address returns the next address where you can receive CKB. Once this address has a transaction the same call will return a new address. This method of creating a new address every time increases the security.