Skip to Content
📢 Breaking change: Applications using LedgerJS for transport implementation should migrate to the Device Management Kit (DMK). Learn more.
DocumentationLedger WalletDiscoverIntegration walkthroughsWallet APIServerHow to replace useWalletAPIServer

How to replace useWalletAPIServer

☞ The renaming of “Ledger Live” to “Ledger Wallet” and “wallet” (in the hardware sense) to “signer” is still in progress. This page may contain legacy references that will be updated.

This guide shows you how to create a Wallet API server after @ledgerhq/wallet-api-server 3.0.0, which no longer exports useWalletAPIServer.

The React hook that used to ship in @ledgerhq/wallet-api-server is removed. Import WalletAPIServer and construct it yourself. Ledger Wallet still has its own hook of the same name in libs/ledger-live-common/src/wallet-api/react.ts. That hook is internal. It is not the removed package export.

Applies to: @ledgerhq/wallet-api-server 3.0.0 and later. Version 2.0.0 already removed the RxJS dependency, the observable fields (accounts$, currencies$, and the rest), and setAccounts() and setCurrencies(). Wallet handlers take an accountId string. The server requires the account.list and currency.list wallet handlers.

Step 1: Construct the server

transport and config are required. logger defaults to the package logger. customHandlers defaults to an empty object.

import { WalletAPIServer } from "@ledgerhq/wallet-api-server"; const server = new WalletAPIServer( transport, config, logger, customHandlers, );

A Ledger Wallet webview that only passes the transport and the config is shown in Example using the constructor. The constructor is constructor(transport: Transport, config: ServerConfig, logger = defaultLogger, customHandlers: CustomHandlers = {}) in packages/server/src/WalletAPIServer.ts.

Step 2: Keep the server in your own hook if you need React state

The package does not store the server in a ref for you. If the server must follow React’s lifecycle, write a hook in your application that constructs WalletAPIServer and returns the instance and your message callback. Ledger Wallet does this in useWalletAPIServer inside libs/ledger-live-common/src/wallet-api/react.ts. That function returns server, onLoad, onReload, onLoadError, and widgetLoaded. It constructs a BridgeSessionWalletAPIServer, which extends WalletAPIServer, from the bridge session, the config, and the merged handlers.

The Ledger Wallet example walks through that internal hook. Copy the pattern only if you are embedding a server the way Ledger Wallet does. A Live App that talks to Ledger Wallet uses the client, not this server.

The package hook is gone, and your server is created with new WalletAPIServer(...). See the server introduction for the role of the server, and the changelog  for the 2.0.0 and 3.0.0 notes.

Last updated on
Ledger
Copyright Š Ledger SAS. All rights reserved. Ledger, Ledger Stax, Ledger Flex, Ledger Nano, Ledger Nano S, Ledger OS, Ledger Wallet, [LEDGER] (logo), [L] (logo) are trademarks owned by Ledger SAS.