Provides Ledger hardware wallet support for Amino transaction signing. Implements the OfflineAminoSigner interface, making it compatible with SigningStargateClient and SigningCosmWasmClient.
npm install @cosmjs/ledger-amino
Requires the Cosmos app installed on your Ledger device and a transport library like @ledgerhq/hw-transport-webusb (browser) or @ledgerhq/hw-transport-node-hid (Node.js).
LedgerSigner
Implements OfflineAminoSigner using a Ledger hardware wallet.
| Method | Parameters | Returns |
|---|
constructor | transport: Transport, options?: LedgerConnectorOptions | LedgerSigner |
getAccounts | — | Promise<readonly AccountData[]> |
signAmino | signerAddress: string, signDoc: StdSignDoc | Promise<AminoSignResponse> |
showAddress | path?: HdPath | Promise<AddressAndPubkey> (asks the device to display an address for user confirmation) |
Options
interface LedgerConnectorOptions {
readonly hdPaths?: readonly HdPath[];
readonly prefix?: string;
readonly testModeAllowed?: boolean;
readonly ledgerAppName?: string;
readonly minLedgerAppVersion?: string;
}
Usage
import TransportWebUSB from "@ledgerhq/hw-transport-webusb";
import { LedgerSigner } from "@cosmjs/ledger-amino";
import { makeCosmoshubPath } from "@cosmjs/amino";
import { SigningStargateClient, GasPrice } from "@cosmjs/stargate";
const transport = await TransportWebUSB.create();
const signer = new LedgerSigner(transport, {
hdPaths: [makeCosmoshubPath(0)],
prefix: "cosmos",
});
const [{ address }] = await signer.getAccounts();
const client = await SigningStargateClient.connectWithSigner(
"https://rpc.my-chain.network",
signer,
{ gasPrice: GasPrice.fromString("0.025uatom") },
);
const result = await client.sendTokens(
address,
"cosmos1recipient...",
[{ denom: "uatom", amount: "1000000" }],
"auto",
);
LedgerConnector
Low-level interface for direct communication with the Cosmos Ledger app.
| Method | Parameters | Returns |
|---|
constructor | transport: Transport, options?: LedgerConnectorOptions | LedgerConnector |
getCosmosAppVersion | — | Promise<string> |
getPubkey | hdPath?: HdPath | Promise<Uint8Array> |
getPubkeys | — | Promise<readonly Uint8Array[]> (one per configured HD path) |
getCosmosAddress | pubkey?: Uint8Array | Promise<string> |
sign | message: Uint8Array, hdPath?: HdPath | Promise<Uint8Array> |
showAddress | hdPath?: HdPath | Promise<AddressAndPubkey> |
Types
interface AddressAndPubkey {
readonly address: string;
readonly pubkey: Secp256k1Pubkey;
}
When constructing LedgerConnector without options, these defaults apply: ledgerAppName is "Cosmos", minLedgerAppVersion is "1.5.3", testModeAllowed is false, prefix is "cosmos", and hdPaths defaults to [makeCosmoshubPath(0)].