# @usebutr/ledger (/api/ledger)



Ledger hardware-wallet adapter (WebUSB). Requires the optional peer
dependency `@ledgerhq/hw-transport-webusb` plus the per-platform Ledger app
module:

* `@ledgerhq/hw-app-eth` for EVM
* `@ledgerhq/hw-app-solana` for SVM
* `@ledgerhq/hw-app-sui` for Sui
* `@ledgerhq/hw-app-btc` for Bitcoin

Each app module is loaded dynamically; you only pay for the ones you actually use.

## Factories [#factories]

### `createLedgerAdapter(options): Promise<WalletAdapter>` [#createledgeradapteroptions-promisewalletadapter]

Unified factory. Dispatches to the per-platform factory based on
`options.platform`. The discriminant is always required.

```ts
// EVM
await createLedgerAdapter({ platform: "evm", chainId: 1, accountCount: 3 });

// SVM
await createLedgerAdapter({ platform: "svm", cluster: "mainnet" });

// Sui
await createLedgerAdapter({ platform: "sui", cluster: "mainnet" });

// Bitcoin
await createLedgerAdapter({ platform: "bitcoin", addressFormat: "bech32" });
```

### Per-platform factories [#per-platform-factories]

Each factory is also exported directly:

* `createEvmLedgerAdapter(options: EvmLedgerOptions): Promise<WalletAdapter>`
* `createSvmLedgerAdapter(options: SvmLedgerOptions): Promise<WalletAdapter>`
* `createSuiLedgerAdapter(options: SuiLedgerOptions): Promise<WalletAdapter>`
* `createBitcoinLedgerAdapter(options: BitcoinLedgerOptions): Promise<WalletAdapter>`

The dispatch's `default` branch is a true `never` exhaustiveness check — every
`ChainPlatform` variant is covered today.

## Options [#options]

### `EvmLedgerOptions` [#evmledgeroptions]

| Field                  | Type                | Default               |
| ---------------------- | ------------------- | --------------------- |
| `platform`             | `"evm"` (required)  | —                     |
| `chainId`              | `number`            | `1`                   |
| `accountCount`         | `number`            | `1`                   |
| `derivationPathPrefix` | `string`            | `"44'/60'/0'/0"`      |
| `id`                   | `string`            | `"ledger"`            |
| `name`                 | `string`            | `"Ledger"`            |
| `icon`                 | `string`            | `LEDGER_DEFAULT_ICON` |
| `loadEth`              | `EthAppConstructor` | DI for tests          |
| `transportFactory`     | `TransportFactory`  | DI for tests          |

### `SvmLedgerOptions` [#svmledgeroptions]

| Field                  | Type                   | Default                   |
| ---------------------- | ---------------------- | ------------------------- |
| `platform`             | `"svm"` (required)     | —                         |
| `cluster`              | `SolanaCluster`        | `"mainnet"`               |
| `accountCount`         | `number`               | `1`                       |
| `derivationPathPrefix` | `string`               | `"44'/501'/0'"`           |
| `id` / `name` / `icon` | `string`               | `LEDGER_SVM_DEFAULT_ICON` |
| `loadSolana`           | `SolanaAppConstructor` | DI for tests              |
| `transportFactory`     | `TransportFactory`     | DI for tests              |

### `SuiLedgerOptions` [#suiledgeroptions]

| Field                  | Type                | Default                   |
| ---------------------- | ------------------- | ------------------------- |
| `platform`             | `"sui"` (required)  | —                         |
| `cluster`              | `SuiCluster`        | `"mainnet"`               |
| `accountCount`         | `number`            | `1`                       |
| `derivationPathPrefix` | `string`            | `"44'/784'/0'/0'"`        |
| `id` / `name` / `icon` | `string`            | `LEDGER_SUI_DEFAULT_ICON` |
| `loadSui`              | `SuiAppConstructor` | DI for tests              |
| `transportFactory`     | `TransportFactory`  | DI for tests              |

### `BitcoinLedgerOptions` [#bitcoinledgeroptions]

| Field                  | Type                                          | Default                       |
| ---------------------- | --------------------------------------------- | ----------------------------- |
| `platform`             | `"bitcoin"` (required)                        | —                             |
| `chainId`              | `string` (CAIP-2)                             | `"bip122:0000…1e93"` mainnet  |
| `addressFormat`        | `"legacy" \| "p2sh" \| "bech32" \| "bech32m"` | `"bech32"`                    |
| `accountCount`         | `number`                                      | `1`                           |
| `derivationPathPrefix` | `string`                                      | `"84'/0'/0'/0"`               |
| `id` / `name` / `icon` | `string`                                      | `LEDGER_BITCOIN_DEFAULT_ICON` |
| `loadBtc`              | `BtcAppConstructor`                           | DI for tests                  |
| `transportFactory`     | `TransportFactory`                            | DI for tests                  |

`LedgerOptions = EvmLedgerOptions | SvmLedgerOptions | SuiLedgerOptions | BitcoinLedgerOptions`.

## Constants [#constants]

* `LEDGER_DEFAULT_ICON: string` — EVM default SVG.
* `LEDGER_SVM_DEFAULT_ICON: string` — SVM default SVG.
* `LEDGER_SUI_DEFAULT_ICON: string` — Sui default SVG.
* `LEDGER_BITCOIN_DEFAULT_ICON: string` — Bitcoin default SVG.
* `LEDGER_CAPABILITIES: WalletCapabilities` — signing-only baseline. Sui
  overrides `signMessage: false` since `@ledgerhq/hw-app-sui` doesn't expose
  `signPersonalMessage` at the current version.

## Types [#types]

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

See the [Ledger connector guide](/connectors/ledger) for browser-support,
per-platform capabilities, and signing-only caveats.

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