Skip to Content
butr
Core concepts

Connectors and wallets

Every wallet is a WalletAdapter: the Connector half is what butr calls, the Wallet half is what your app calls.

A WalletAdapter is a Connector intersected with a platform wallet surface (EvmWallet, SvmWallet, SuiWallet, BitcoinWallet, or PolkadotWallet). The split is documentary: it names which half butr drives and which half your app calls. In both halves, an optional member is defined only when it works for that wallet; see capabilities.

Connector: what butr calls

The manager calls these during connect, disconnect, and hydration. You rarely touch them directly.

type Connector<P extends ChainPlatform = ChainPlatform> = {
  chainPlatform: P;
  connect: () => Promise<void>;
  disconnect?: () => Promise<void>;
  /** Every exposed account, active first. Empty when not connected. */
  getAccounts: () => Promise<ReadonlyArray<Account>>;
  icon?: string;
  id: string; // stable key: "io.metamask", "wallet-standard:svm-phantom"
  name: string; // UI-facing: "MetaMask", "Phantom"
  requestAccounts?: () => Promise<void>;
  /** Hydration's silent reconnect; defined only where it can succeed
   *  without a prompt. */
  restore?: () => Promise<void>;
  subscribe?: (listener: (event: ConnectorEvent) => void) => () => void;
  walletKey: string; // the same on every adapter of one wallet: "phantom"
};

type ConnectorEvent =
  { accounts: ReadonlyArray<Account>; type: "accountsChanged" } | { type: "disconnected" };

subscribe is how wallet-side events reach butr: an account switch or a chain switch arrives as accountsChanged with the new list, active first. Adapters forward the wallet's list as is, so accountsChanged with an empty list means disconnected. disconnected is for signals that end the session itself: a Wallet Standard wallet unregistering, a WalletConnect session deleted by the wallet, an EIP-1193 disconnect. You never wire accountsChanged / chainChanged yourself.

Wallet: what your app calls

butr never invokes these itself, apart from getSigner in useSigner(), getBalance in useBalance(), and signIn or signMessage in createSignInFlow. Tx is the platform's transaction type.

type WalletBase<Tx> = {
  getBalance?: (options?: { account?: Account; token?: string }) => Promise<Balance>;
  getSigner: () => Promise<WalletSigner>;
  getTransactionReceipt?: (hash: string) => Promise<TransactionReceipt>;
  sendTx?: (tx: Tx, options?: { account?: Account; chain?: ChainBase }) => Promise<string>;
  signMessage?: (message: Uint8Array, options?: { account?: Account }) => Promise<SignedMessage>;
  switchChain?: (chain: ChainBase) => Promise<void>;
};

The platform types add their own members and fix Tx:

TypeTxAdds
EvmWalletEvmTransactionRequestnothing: EVM wallets sign and send in one eth_sendTransaction
SvmWalletUint8ArraysignIn (SIWS), signTransaction → signed transaction bytes
SuiWalletSuiTransactionInputsignTransaction → { bytes, signature }
BitcoinWalletBitcoinTransfersignTransaction on PSBT bytes → signed PSBT bytes
PolkadotWalletnoneno sendTx: extrinsics go through getSigner() and polkadot-api

account must be one the wallet exposes; omit it to use the active account. An unknown account rejects with AccountNotExposed rather than silently signing with another, and a wallet that exposes none rejects with NotConnected. chain targets one transaction, and a chain the transport cannot reach rejects with ChainMismatch; see chains and accounts for how each transport routes it.

signMessage returns both signature and signedMessage. Solana Wallet Standard wallets may prefix or re-encode the message internally. Verify the signature against signedMessage, not your input bytes. EVM wallets echo the input.

The seam: sources

Every adapter reaches the manager through WalletManagerConfig.sources, a list of WalletSource functions. Discovery and built adapters use the same seam:

import type { WalletManagerConfig } from "@usebutr/core";
import { fromAdapters } from "@usebutr/core";
import { autoDiscovery } from "@usebutr/wallets";
import { createWalletConnectAdapters } from "@usebutr/walletconnect";

const config: WalletManagerConfig = {
  sources: [
    autoDiscovery(), // injected and Wallet Standard wallets
    fromAdapters(createWalletConnectAdapters({ … })), // built adapters
  ],
};

fromAdapters takes one adapter, several, or a promise of either, and a rejected promise is logged and contributes nothing. Every adapter from every source lands in useDiscoveredWallets(), so a picker lists WalletConnect and Ledger next to MetaMask with no extra metadata. The first adapter announced for an id wins.

This is why "how do I add wallet X" always has the same shape: injected, WalletConnect, Ledger, or a hand-written adapter all arrive as a source. A hand-written adapter takes its chain and account rules from the chain targets in @usebutr/core, and the adapter contract suite checks it behaves like the built-in ones.

ConnectedWallet

What the hooks hand back:

type ConnectedWallet<P extends ChainPlatform = ChainPlatform> = {
  account: Account; // the active account; always one of `accounts`
  accounts: ReadonlyArray<Account>; // every account the wallet exposed
  connector: AdapterByPlatform[P]; // the platform's adapter type
};

Account is { chain: ChainBase; id: string; walletAddress: string }, built with buildAccount(address, chain). The chain travels inside the account, so a chain switch arrives as the same address with new chain data. ConnectedWallet<"svm"> narrows connector to SvmAdapter; get one from useSelectedWallet("svm") or isPlatformWallet(wallet, "svm").

Source: packages/core/src/types/connector.ts, packages/core/src/types/wallet.ts, packages/core/src/wallet-source.ts.