Get account details from wallet

Extract addresses, keys, and other account information from a wallet instance

import { STACKS_TESTNET, STACKS_MAINNET } from "@stacks/network";
import { generateWallet, getStxAddress } from "@stacks/wallet-sdk";
// Generate or restore wallet
const wallet = await generateWallet({
secretKey: "your twenty four word mnemonic phrase goes here...",
password: "wallet-password",
});
// Get first account
const account = wallet.accounts[0];
// Get addresses for different networks
const testnetAddress = getStxAddress({
account,
transactionVersion: 0 // testnet
});
const mainnetAddress = getStxAddress({
account,
transactionVersion: 1 // mainnet
});
// Get keys
const privateKey = account.stxPrivateKey;
const publicKey = account.stxPublicKey;
console.log("Testnet address:", testnetAddress);
console.log("Mainnet address:", mainnetAddress);
console.log("Public key:", publicKey);

Use cases

  • Displaying user addresses in wallet UIs
  • Getting private keys for transaction signing
  • Deriving addresses for different networks
  • Building wallet management tools

Key concepts

Wallet accounts contain:

  • Private key: Used for signing transactions
  • Public key: Derived from private key
  • Addresses: Network-specific (mainnet vs testnet)
  • Derivation path: BIP44 path used to generate the account