Overview

The @sei-js/ledger package provides TypeScript helper functions for integrating with the SEI Ledger hardware wallet app. It enables secure transaction signing and address derivation for Sei blockchain applications using Ledger devices.

Installation

yarn add @sei-js/ledger

Core Functions

createTransportAndApp

Creates a transport connection and app instance for communicating with the Ledger device.

Parameters:

  • None

Returns:

  • Promise<{transport: Transport, app: SeiApp}> - Object containing transport and app instances
import { createTransportAndApp } from '@sei-js/ledger';

const { transport, app } = await createTransportAndApp();
console.log(transport, app);

getAddresses

Retrieves both EVM and Cosmos addresses from the Ledger device for a given derivation path.

Parameters:

  • app (SeiApp) - An instance of the Ledger Sei app
  • path (string) - HD derivation path (e.g., “m/44’/60’/0’/0/0”)

Returns:

  • Promise<{evmAddress: string, nativeAddress: string}> - Object containing both address types
import { getAddresses } from '@sei-js/ledger';

const { evmAddress, nativeAddress } = await getAddresses(app, "m/44'/60'/0'/0/0");
console.log(evmAddress, nativeAddress);

SeiLedgerOfflineAminoSigner

A signer class that enables offline amino signing with Ledger devices, compatible with CosmJS.

Constructor

new SeiLedgerOfflineAminoSigner(app: SeiApp, path: string)

Parameters:

  • app (SeiApp) - An instance of the Ledger Sei app
  • path (string) - HD derivation path (e.g., “m/44’/60’/0’/0/0”)
import { SeiLedgerOfflineAminoSigner } from '@sei-js/ledger';

const ledgerSigner = new SeiLedgerOfflineAminoSigner(app, "m/44'/60'/0'/0/0");

getAccounts

Retrieves account information from the Ledger device.

Returns:

  • Promise<readonly AccountData[]> - Array of AccountData objects with address and public key
const accounts = await ledgerSigner.getAccounts();
console.log(accounts); 
// { address: 'sei1...', pubkey: { type: 'tendermint/PubKeySecp256k1', value: '...' } }

signAmino

Signs a transaction document using the Ledger device.

Parameters:

  • _signerAddress (string) - The address of the signer (unused)
  • signDoc (StdSignDoc) - The sign document to be signed

Returns:

  • Promise<AminoSignResponse> - Object containing the signed document and signature
import { StdSignDoc } from '@cosmjs/amino';

const signDoc: StdSignDoc = { /* your StdSignDoc object */ };
const signResponse = await ledgerSigner.signAmino('sei123...', signDoc);
console.log(signResponse.signed, signResponse.signature);

Complete Example

Here’s a complete example showing how to use the ledger package to delegate tokens:

import { coins, SigningStargateClient, StdFee } from "@cosmjs/stargate";
import { createTransportAndApp, getAddresses, SeiLedgerOfflineAminoSigner } from "@sei-js/ledger";

const testApp = async () => {
  const validatorAddress = "seivaloper1sq7x0r2mf3gvwr2l9amtlye0yd3c6dqa4th95v";
  const rpcUrl = "https://rpc-testnet.sei-apis.com/";
  const memo = "Delegation";
  const path = "m/44'/60'/0'/0/0";

  // Create connection to Ledger device
  const { app } = await createTransportAndApp();
  
  // Get addresses from Ledger
  const { nativeAddress } = await getAddresses(app, path);
  
  // Create signer instance
  const ledgerSigner = new SeiLedgerOfflineAminoSigner(app, path);
  
  // Connect to Sei network
  const signingStargateClient = await SigningStargateClient.connectWithSigner(
    rpcUrl, 
    ledgerSigner
  );

  // Create delegation message
  const msgDelegate = {
    typeUrl: "/cosmos.staking.v1beta1.MsgDelegate",
    value: {
      delegatorAddress: nativeAddress.address,
      validatorAddress: validatorAddress,
      amount: coins(500, "usei"),
    },
  };

  // Set transaction fee
  const fee: StdFee = {
    amount: [{ denom: "usei", amount: "20000" }],
    gas: "200000",
  };

  // Sign and broadcast transaction
  const result = await signingStargateClient.signAndBroadcast(
    nativeAddress.address, 
    [msgDelegate], 
    fee, 
    memo
  );
  
  console.log("Broadcast result:", result);
};

testApp();

Security Notes

  • Ensure your Ledger device is genuine and purchased from official sources
  • Always verify transaction details on your Ledger device screen before confirming
  • Keep your Ledger device firmware updated
  • Store your recovery phrase securely and never share it

Hardware Requirements

  • Ledger Nano S Plus, Nano X, or compatible device
  • SEI app installed on the Ledger device
  • USB or Bluetooth connection to your computer