API reference
This page describes the public API of Ledger Wallet Provider: initializeLedgerProvider from @ledgerhq/ledger-wallet-provider.
initializeLedgerProvider(options)
See Configuration for the full options reference with defaults and examples.
Signature
function initializeLedgerProvider(
options: InitializeLedgerProviderOptions
): () => void
type InitializeLedgerProviderOptions = {
// Core options
apiKey: string; // Your Ledger API key
dAppIdentifier: string; // Your dApp identifier
loggerLevel?: 'fatal' | 'error' | 'warn' | 'info' | 'debug'; // default: 'info'
blockchainProviderFactories: BlockchainProviderFactoryRegistration[]; // v2+ only: blockchain families to register
// UI options
target?: HTMLElement; // Where to mount the UI (default: document.body)
hideButton?: boolean; // Hide the floating button entirely (default: false)
floatingButtonPosition?: 'bottom-right' | 'bottom-left' | 'bottom-center' | 'top-right' | 'top-left' | 'top-center' | 'middle-right'; // Position of the floating button (default: 'bottom-right')
floatingButtonTarget?: HTMLElement | string; // Element or CSS selector to anchor the floating button to
walletTransactionFeatures?: Array<'send' | 'receive' | 'swap' | 'buy' | 'earn' | 'sell'>; // Wallet action CTAs to display
transactionConfirmationNotification?: 'tooltip' | 'toast'; // How TX confirmation is shown (default: 'tooltip')
};apiKey, dAppIdentifierandblockchainProviderFactories are shown as required because the provider cannot authenticate or register a chain without them. Note that the TypeScript type still marks all three optional for backward compatibility, so the compiler will not catch a missing one.
Returns a cleanup function. Call it to remove the UI components from the DOM and to unregister any providers that were registered for your partner configuration (for example the EVM eip6963:requestProvider listener and/or 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.
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 — install and initialize the provider
- EVM — EVM Blockchain Provider
- Solana — Solana Blockchain Provider
- Configuration — full
initializeLedgerProvideroptions reference - Requirements — browser and platform requirements
- EIP-1193 specificationÂ
- EIP-6963 specificationÂ