Skip to Content
butr
API reference

@usebutr/ledger

Per-platform Ledger factories (EVM, SVM, Sui, Bitcoin), their options, and the device-app signers.

Ledger hardware wallets over WebUSB. The manifest declares all five @ledgerhq/* packages as required peer dependencies, so install them all; each is loaded on first connect:

  • @ledgerhq/hw-transport-webusb, the default transport
  • @ledgerhq/hw-app-eth for EVM
  • @ledgerhq/hw-app-solana for SVM
  • @ledgerhq/hw-app-sui for Sui
  • @ledgerhq/hw-app-btc for Bitcoin

Factories

createLedgerAdapter(options: LedgerOptions): WalletAdapterFor<"bitcoin" | "evm" | "sui" | "svm">

Dispatches on options.platform to the per-platform factory; import that factory directly for the narrower adapter type. The adapter is un-paired until connect(); hand it to the manager with fromAdapters:

import type { WalletManagerConfig } from "@usebutr/core";
import { EVM_CHAINS, fromAdapters } from "@usebutr/core";
import { createLedgerAdapter } from "@usebutr/ledger";

const config: WalletManagerConfig = {
  sources: [
    fromAdapters(
      createLedgerAdapter({ chainId: EVM_CHAINS.sepolia.id, id: "ledger-evm", platform: "evm" }),
    ),
    fromAdapters(createLedgerAdapter({ accountCount: 3, id: "ledger-svm", platform: "svm" })),
  ],
};

Every factory is synchronous and returns the adapter. A chainId outside the platform's namespace throws a ChainMismatch ConnectionError at creation.

Per-platform factories

  • createEvmLedgerAdapter(options: EvmLedgerOptions): EvmAdapter
  • createSvmLedgerAdapter(options: SvmLedgerOptions): SvmAdapter
  • createSuiLedgerAdapter(options: SuiLedgerOptions): SuiAdapter
  • createBitcoinLedgerAdapter(options: BitcoinLedgerOptions): BitcoinAdapter

LedgerOptions is the union of the four.

Options

Every factory takes:

FieldTypeDefault
platform"evm" | "svm" | "sui" | "bitcoin"Required.
chainIdstring (CAIP-2)The platform's mainnet. Ledger apps have no network switch: build one adapter per chain.
accountCountnumber1. Addresses read during connect(), one device round trip each.
derivationPathPrefixstringPer platform, below. The account index is appended as the last segment.
idstring"ledger"
namestring"Ledger"
iconstringLEDGER_DEFAULT_ICON
transportTransportFactoryA dynamic import of @ledgerhq/hw-transport-webusb. Pass another @ledgerhq/hw-transport-* factory, such as WebHID.
PlatformDefault chainDefault prefixIndexApp class
evmeip155:144'/60'/0'/0/<n>eth?: EthAppConstructor
svmsolana:mainnet44'/501'/0'/<n>'solana?: SolanaAppConstructor
suisui:mainnet44'/784'/0'/0'/<n>'sui?: SuiAppConstructor
bitcoinbip122:000000000019d6689c085ae165831e9384'/0'/0'/0/<n>btc?: BtcAppConstructor

The app class option (eth, solana, sui, btc) is for an app that already imports it; by default each factory imports the app package dynamically.

BitcoinLedgerOptions adds addressFormat?: BitcoinAddressFormat ("legacy" | "p2sh" | "bech32" | "bech32m", default "bech32"). The default Bitcoin prefix follows it (purpose 44', 49', 84' or 86') and the chain (coin type 0' on mainnet, 1' elsewhere); the table shows the bech32 mainnet one. A custom prefix must agree with the format. Bitcoin testnet needs the Bitcoin Test app and chainId: BITCOIN_CHAINS.testnet.id.

What each adapter defines

A Ledger signs; your chain client reads state and broadcasts. No adapter has sendTx, getBalance, getTransactionReceipt, subscribe, requestAccounts or switchChain.

PlatformsignMessagesignTransaction
evmEIP-191, r ‖ s ‖ vnone: use the signer's app.signTransaction
svmOff-chain messageSerialized transaction, legacy or v0; resolves it signed
suinoneBCS bytes or their base64; resolves { bytes, signature }
bitcoinBIP-137 compact signature over the bytesPSBT bytes; resolves the signed PSBT

Signers

Importing the package registers one kind per app, each carrying the device app bound to the open transport:

kindapp
ledger-evmEthAppLike
ledger-svmSolanaAppLike
ledger-suiSuiAppLike
ledger-bitcoinBtcAppLike

The derivation path of an account is derivationPathPrefix plus its index in getAccounts(). getSigner() rejects with a NotConnected ConnectionError before connect().

Constants

LEDGER_DEFAULT_ICON: the generic Ledger device icon.

Types

LedgerOptions, EvmLedgerOptions, SvmLedgerOptions, SuiLedgerOptions, BitcoinLedgerOptions, BitcoinAddressFormat, EthAppLike, EthAppConstructor, SolanaAppLike, SolanaAppConstructor, SuiAppLike, SuiAppConstructor, BtcAppLike, BtcAppConstructor, TransportLike, TransportFactory.

See the Ledger connector for browser support and signing caveats.

Source: packages/ledger/src/index.ts.