A Dai.js plugin for using Ledger in a browser environment.
import LedgerPlugin from '@makerdao/dai-plugin-ledger-web';
import Maker from '@makerdao/dai';
const maker = await Maker.create('http', {
plugins: [LedgerPlugin],
accounts: {
myLedger1: { type: 'ledger' }
}
});
// this will not resolve until the Ledger account is set up
await maker.authenticate();
// or you can defer setting the account up until later
await maker.addAccount('myLedger2', { type: 'ledger' });
accountsLength
: Set this to the number of accounts to fetch. Must also setchoose
if greater than 1; see below. (Default: 1)accountsOffset
: Set this to the index offset number to fetch accounts from (Default: 0)path
: Set this to the derivation path to use. (Default: "44'/60'/0'/0/0")legacy
: Set this to use the old Ledger address derivation method. More info
await maker.addAccount('myLedger', {
type: 'ledger',
accountsLength: 10,
choose: (addresses, callback) => {
// show the list of addresses in your UI and have the user pick one; then
// call the callback with the chosen address. `addAccount` will not resolve
// until the callback is called. if you pass an error object as the first
// argument, `addAccount` will throw it.
setTimeout(() => callback(null, addresses[7]), 20000);
}
});
You can find an example of this plugin being used in an app here.
yarn
// version bump on package.json
yarn build
cd /dist
npm publish