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. Announces the Ledger wallet to every supported chain through its native discovery protocol: EVM dApps via EIP-6963 , and Solana dApps via the Wallet Standard (discoverable through @solana/wallet-adapter and similar libraries).
Signature
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 for the full options reference with defaults and examples.
Returns a cleanup function. Call it to remove the UI components from the DOM and to unregister every chain provider — both the EVM eip6963:requestProvider listener and the Solana Wallet Standard wallet.
const cleanup = initializeLedgerProvider({ /* options */ })
// When unmounting (e.g. route change, app teardown):
cleanup()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.
LedgerEIP1193Provider
Implements the EIP-1193 Ethereum Provider JavaScript API for Ledger hardware signers.
You obtain an instance via the eip6963:announceProvider event (see Get started):
window.addEventListener('eip6963:announceProvider', (event: CustomEvent) => {
const { provider } = event.detail // LedgerEIP1193Provider
})
window.dispatchEvent(new Event('eip6963:requestProvider'))Methods
request(args): Promise<unknown>
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.
on(eventName, listener): this
on<TEvent extends keyof ProviderEvent>(
eventName: TEvent,
listener: (args: ProviderEvent[TEvent]) => void,
): thisRegisters an event listener. Returns this for chaining.
removeListener(eventName, listener): this
removeListener<TEvent extends keyof ProviderEvent>(
eventName: TEvent,
listener: (args: ProviderEvent[TEvent]) => void,
): thisRemoves a previously registered listener. Returns this for chaining.
isConnected(): boolean
isConnected(): booleanReturns true if the provider has a connected account.
disconnect(code?, message?, data?): Promise<void>
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 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 ) |
eth_signTypedData | Signs typed structured data (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 — how to initialize the provider and connect accounts
- Configuration — full
initializeLedgerProvideroptions reference - Requirements — browser and platform requirements
- EIP-1193 specification
- EIP-6963 specification