getDefaultWallet & setDefaultWalle

Sats Connect lets your app manage your user's default connected wallet:

  • the getDefaultWallet() method lets you fetch the user's default connected wallet

  • the setDefaultWallet() method lets you set the user’s default connected wallet

The default selection is stored in local storage.

No request parameters are required for the above methods. The following snippet shows how to manage the user’s default wallet:

import { getDefaultWallet, setDefaultWallet } from "@sats-connect/core";
import { selectWallet } from "@sats-connect/ui"

async function example() {
  const defaultWallet = await getDefaultWallet();
  
  if (defaultWallet) {
    return new WalletProvider(defaultWallet);
  }
  
  const selectedWallet = await selectWallet();
  await setDefaultWallet(selectedWallet);
}

Note that this is handled automatically when using Wallet.request methods

  • The method will check for a default connected wallet first.

  • If there is no connected wallet, the user will be prompted to select one first. The method will then set it as new default connected wallet.