---
title: API reference
category: reference
---

# API reference

This page describes the public API of `@ledgerhq/ledger-wallet-provider`: the `initializeLedgerProvider` function and the `LedgerEIP1193Provider` class.

---

## `initializeLedgerProvider(options)`

Initializes the Ledger Wallet Provider and injects the UI components into the DOM. Registers the provider with the [EIP-6963](https://eips.ethereum.org/EIPS/eip-6963) discovery protocol.

**Signature**

```ts
function initializeLedgerProvider(
  options: InitializeLedgerProviderOptions
): () => void

type InitializeLedgerProviderOptions = {
  // Core
  apiKey?: string;
  dAppIdentifier?: string;
  loggerLevel?: 'fatal' | 'error' | 'warn' | 'info' | 'debug';
  environment?: 'staging' | 'production';
  dmkConfig?: DeviceModuleOptions;

  // UI
  target?: HTMLElement;
  hideButton?: boolean;
  floatingButtonPosition?:
    | 'bottom-right'
    | 'bottom-left'
    | 'bottom-center'
    | 'top-right'
    | 'top-left'
    | 'top-center'
    | 'middle-right';
  floatingButtonTarget?: HTMLElement | string;
  walletTransactionFeatures?: Array<
    'send' | 'receive' | 'swap' | 'buy' | 'earn' | 'sell'
  >;

  // Development
  devConfig?: {
    stub?: {
      base?: boolean;
      account?: boolean;
      balance?: boolean;
      device?: boolean;
      web3Provider?: boolean;
      dAppConfig?: boolean;
      transactionHistory?: boolean;
    };
  };
};
```

See [Configuration](./configuration) for the full `options` reference with defaults and examples.

**Returns** a cleanup function. Call it to remove the provider and UI components from the DOM and to deregister the `eip6963:requestProvider` listener.

```ts
const cleanup = initializeLedgerProvider({ /* options */ })

// When unmounting (e.g. route change, app teardown):
cleanup()
```

> **Note:** If the browser does not support Web HID or Web Bluetooth, `initializeLedgerProvider` returns a no-op function without registering the provider or mounting any UI. See [Requirements](./requirements).

---

## `LedgerEIP1193Provider`

Implements the [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193) Ethereum Provider JavaScript API for Ledger hardware signers.

You obtain an instance via the `eip6963:announceProvider` event (see [Get started](./get-started)):

```ts
window.addEventListener('eip6963:announceProvider', (event: CustomEvent) => {
  const { provider } = event.detail // LedgerEIP1193Provider
})
window.dispatchEvent(new Event('eip6963:requestProvider'))
```

### Methods

#### `request(args): Promise<unknown>`

```ts
request({ method, params }: RequestArguments): Promise<unknown>
```

Makes a JSON-RPC request to the provider. For signing and account-selection methods, the provider queues the request while the Ledger UI is open and executes it when the UI closes. Rejects with a `ProviderRpcError` on failure.

For the full list of supported methods, see [Supported methods](#supported-methods).

#### `on(eventName, listener): this`

```ts
on<TEvent extends keyof ProviderEvent>(
  eventName: TEvent,
  listener: (args: ProviderEvent[TEvent]) => void,
): this
```

Registers an event listener. Returns `this` for chaining.

#### `removeListener(eventName, listener): this`

```ts
removeListener<TEvent extends keyof ProviderEvent>(
  eventName: TEvent,
  listener: (args: ProviderEvent[TEvent]) => void,
): this
```

Removes a previously registered listener. Returns `this` for chaining.

#### `isConnected(): boolean`

```ts
isConnected(): boolean
```

Returns `true` if the provider has a connected account.

#### `disconnect(code?, message?, data?): Promise<void>`

```ts
disconnect(code?: number, message?: string, data?: unknown): Promise<void>
```

Disconnects the provider, clears the selected account and chain, and fires a `disconnect` event. The `code` parameter follows the [CloseEvent status code](https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent/code) convention (default: `1000`).

---

### Supported methods

**Handled locally by the provider**

| Method                       | Description                                                                        |
| ---------------------------- | ---------------------------------------------------------------------------------- |
| `eth_requestAccounts`        | Opens the Ledger UI for signer and account selection; returns the selected address |
| `eth_accounts`               | Returns the currently selected account address                                     |
| `eth_chainId`                | Returns the current chain ID as a hex string                                       |
| `eth_sendTransaction`        | Signs and broadcasts a transaction                                                 |
| `eth_signTransaction`        | Signs a transaction without broadcasting                                           |
| `eth_signRawTransaction`     | Signs a raw transaction                                                            |
| `eth_sendRawTransaction`     | Signs and broadcasts a raw transaction                                             |
| `eth_sign`                   | Signs a message                                                                    |
| `personal_sign`              | Signs a personal message ([EIP-191](https://eips.ethereum.org/EIPS/eip-191))       |
| `eth_signTypedData`          | Signs typed structured data ([EIP-712](https://eips.ethereum.org/EIPS/eip-712))    |
| `eth_signTypedData_v4`       | Signs typed structured data v4 (EIP-712)                                           |
| `wallet_switchEthereumChain` | Switches to a supported chain ID                                                   |

**Forwarded to node RPC**

| Method            | Description                         |
| ----------------- | ----------------------------------- |
| `eth_blockNumber` | Returns the current block number    |
| `eth_getBalance`  | Returns the balance of an address   |
| `eth_getCode`     | Returns the code at a given address |
| `eth_estimateGas` | Estimates gas for a transaction     |
| `eth_call`        | Executes a read-only call           |

### Events

| Event             | Payload type                      | Fires when                            |
| ----------------- | --------------------------------- | ------------------------------------- |
| `accountsChanged` | `string[]`                        | The selected account changes          |
| `chainChanged`    | `string` (hex chain ID)           | The active chain changes              |
| `connect`         | `{ chainId: string }`             | The provider connects with an account |
| `disconnect`      | `ProviderRpcError`                | The provider disconnects              |
| `message`         | `{ type: string; data: unknown }` | The provider emits a message          |

### Error codes

`request()` rejects with a `ProviderRpcError` whose `code` is one of the following:

| Code     | Name                  | When it occurs                                                                |
| -------- | --------------------- | ----------------------------------------------------------------------------- |
| `4001`   | `UserRejectedRequest` | User rejected the request or closed the modal                                 |
| `4100`   | `Unauthorized`        | Provider not connected, no account selected, or address mismatch              |
| `4200`   | `UnsupportedMethod`   | Method is not in the supported list                                           |
| `4900`   | `Disconnected`        | Provider is disconnected when a method that requires a connection is called   |
| `4901`   | `ChainDisconnected`   | Requested chain is not in the supported chain list                            |
| `-32602` | `InvalidParams`       | Invalid parameters (e.g. malformed typed data)                                |
| `-32603` | `InternalError`       | Internal error (e.g. provider busy, broadcast failed, blind signing disabled) |

---

## See also

- [Get started](./get-started) — how to initialize the provider and connect accounts
- [Configuration](./configuration) — full `initializeLedgerProvider` options reference
- [Requirements](./requirements) — browser and platform requirements
- [EIP-1193 specification](https://eips.ethereum.org/EIPS/eip-1193)
- [EIP-6963 specification](https://eips.ethereum.org/EIPS/eip-6963)
