API reference
This page describes the public API of Ledger Wallet Provider: initializeLedgerProvider from @ledgerhq/ledger-wallet-provider, and LedgerEIP1193Provider from @ledgerhq/ledger-wallet-provider-evm.
initializeLedgerProvider(options)
Initializes the Ledger Wallet Provider and injects the UI components into the DOM. Registers blockchain providers for each factory you pass in blockchainProviderFactories that is also enabled in your partner dApp configuration (dAppIdentifier): EVM factory + Ethereum enabled → EIP-6963 / EIP-1193 ; Solana factory + Solana enabled → Wallet Standard . Without factories, no chain provider is registered. For chain-specific connect and signing examples, see EVM and Solana.
Signature
function initializeLedgerProvider(
options: InitializeLedgerProviderOptions
): () => void
type BlockchainFamily = 'ethereum' | 'solana'
type BlockchainProviderFactoryRegistration = {
family: BlockchainFamily
create: (core: CoreFacade, config: BlockchainConfig) => BlockchainProvider
}
type InitializeLedgerProviderOptions = {
// Core
apiKey?: string;
dAppIdentifier?: string;
loggerLevel?: 'fatal' | 'error' | 'warn' | 'info' | 'debug';
environment?: 'staging' | 'production';
dmkConfig?: DeviceModuleOptions;
blockchainProviderFactories?: BlockchainProviderFactoryRegistration[];
// 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'
>;
transactionConfirmationNotification?: 'tooltip' | 'toast';
// Development
devConfig?: {
stub?: {
base?: boolean;
account?: boolean;
balance?: boolean;
device?: boolean;
web3Provider?: boolean;
solanaProvider?: 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 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.
LedgerEIP1193Provider
Implements the EIP-1193Â Ethereum Provider JavaScript API for Ledger hardware signers. Import it from @ledgerhq/ledger-wallet-provider-evm (it is no longer re-exported from @ledgerhq/ledger-wallet-provider).
You obtain an instance via the eip6963:announceProvider event (see EVM):
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 — install and initialize the provider
- EVM — EIP-6963 discovery and EIP-1193 signing how-to
- Solana — Wallet Standard connect and signing how-to
- Configuration — full
initializeLedgerProvideroptions reference - Requirements — browser and platform requirements
- EIP-1193 specificationÂ
- EIP-6963 specificationÂ