truffle-ledger-provider

1.0.3 • Public • Published

truffle-ledger-provider

Ledger Wallet-enabled Web3 provider. Use it to sign transactions with Ledger Nano S or Ledger Blue.

Install

$ npm i truffle-ledger-provider -S

General Usage

You can use this provider wherever a Web3 provider is needed, not just in Truffle. For Truffle-specific usage, see next section.

Before using Ledger Wallet-enabled Web3 provider, you must change your Ledger App configuration as follows:

  • Contract data: Yes
  • Browser Support: No
const LedgerWalletProvider = require('truffle-ledger-provider');
 
const ledgerOptions = {
  networkId: 1, // mainnet
  path: "44'/60'/0'/0", // ledger default derivation path
  askConfirm: false,
  accountsLength: 1,
  accountsOffset: 0
};
 
const provider = new LedgerWalletProvider(ledgerOptions, 'http://localhost:8545');

Parameters:

  • networkId: number. Ethereum network ID. 1-mainnet, 3-ropsten, etc.
  • path: string. HD derivation path.
  • askConfirm: boolean. If true, deployment of each contract must be confirmed.
  • accountsLength: number. Number of accounts to derivate.
  • accountsOffset: number. Offset index to use to start derivating the accounts.

Truffle Usage

You can easily use this within a Truffle configuration. For instance:

truffle.js

const LedgerWalletProvider = require('truffle-ledger-provider');
 
const INFURA_APIKEY = '...'; // set your Infura API key
const ledgerOptions = {}; // use default options
 
module.exports = {
  networks: {
    development: {
      host: 'localhost',
      port: 8545,
      network_id: '*' // Match any network id
    },
    ropsten: {
      provider: new LedgerWalletProvider(ledgerOptions, `https://ropsten.infura.io/${INFURA_APIKEY}`),
      network_id: 3,
      gas: 4600000
    }
  }
};

Debug mode

You can enable the debug mode by passing true on the constructor. For instance:

truffle.js

module.exports = {
  networks: {
    ropsten: {
      provider: new LedgerWalletProvider(ledgerOptions, `https://ropsten.infura.io/${INFURA_APIKEY}`, true), // Enable debug.
      network_id: 3,
      gas: 4600000
    }
  }
};

Contributors

Package Sidebar

Install

npm i truffle-ledger-provider

Weekly Downloads

5

Version

1.0.3

License

MIT

Unpacked Size

4.49 kB

Total Files

5

Last publish

Collaborators

  • petertulala