Generate a wallet

Create a new wallet with mnemonic phrase or restore from existing seed

import { generateWallet, generateSecretKey } from '@stacks/wallet-sdk';
// Generate a new wallet with a new 24-word seed phrase
const secretKey = generateSecretKey(256); // 256 bits = 24 words
const wallet = await generateWallet({
secretKey,
password: 'your-secure-password',
});
// Access the first account
const account = wallet.accounts[0];
console.log('Address:', account.stxAddress);
console.log('Mnemonic:', secretKey);

Use cases

  • Creating new wallets for users
  • Restoring wallets from seed phrases
  • Generating deterministic wallet addresses
  • Building wallet applications

Key concepts

The wallet SDK generates hierarchical deterministic (HD) wallets following BIP32/BIP39 standards:

  • Secret key: Can be a mnemonic phrase or private key
  • Password: Encrypts the wallet (different from mnemonic passphrase)
  • Accounts: Multiple accounts can be derived from one seed