Introduction
Ledger provides APIs and SDKs to integrate hardware wallet functionalities into live applications. This tutorial walks you through creating a secure, live crypto app connected to Ledger devices.
Step 1: Environment Setup
- Install Node.js and npm on your development machine.
- Create a new project folder and initialize it with
npm init
. - Install Ledger SDK packages:
npm install @ledgerhq/hw-app-eth @ledgerhq/hw-transport-node-hid
.
Step 2: Connect to Ledger Device
- Import the transport and app classes:
const TransportNodeHid = require('@ledgerhq/hw-transport-node-hid').default;
const AppEth = require('@ledgerhq/hw-app-eth').default;
const transport = await TransportNodeHid.create();
const eth = new AppEth(transport);
Step 3: Fetch Public Key and Address
Retrieve Ethereum addresses securely:
const result = await eth.getAddress("44'/60'/0'/0/0");
console.log(result.address);
Step 4: Transaction Signing
- Prepare transaction data according to Ethereum specifications.
- Request signature from Ledger device:
const signature = await eth.signTransaction("44'/60'/0'/0/0", txHex);
Step 5: Integrating into Live App
- Integrate Ledger connection logic into your frontend or backend.
- Use transport events to detect device connection and disconnection.
- Ensure all sensitive operations occur on-device, never exposing private keys.
Step 6: Security Best Practices
- Always validate user input before sending to Ledger.
- Confirm transaction details on the Ledger device screen.
- Keep Ledger firmware and SDKs up-to-date.
- Never store private keys in code or environment variables.
FAQs
Q: Can I connect multiple Ledger devices simultaneously?
A: Yes, by opening separate transport connections for each device.
Q: Is it safe to use Ledger SDK in production?
A: Yes, as long as all sensitive operations remain on-device and SDKs are up-to-date.