This web3 provider allows Ethereum transactions to be signed with a Ledger device.
- Lightweight, with minimal dependencies
- Easy to use; just plug it in wherever a web3 provider is expected
$ yarn add web3-provider-ledger
$ npm install --save web3-provider-ledger
Let's assume we are using the
ethjs library. This library, like Web3,
is designed to be constructed with an instance of a web3 provider.
;;const eth = ;
That's all you need to do in order to get an instance of ethjs, but this particular instance is only capable of generating signed transactions.
Here's one way you might end up with a transaction for interacting with a smart contract:
// Use the ethjs contract API to build a convenience wrapper for a contractconst myContract = eth;// Get the raw signed transactionconst tx = await myContract;
At this point,
tx gives us a signed transaction. We still need to send
the transaction, which requires a network-capable provider. For this, you
can use the built-in
Eth.HttpProvider or look for an injected provider
via the global
Here's what this might look like:
// Constract a network-capable instance of ethjsconst ethNet = web3currentProvider;// Use the network-capable provider to *send* the transactionconst txId = await ethNet;
See the API Reference for detailed code-level documentation.
In addition to the provider, this library includes a
which allows operations to be performed directly on the device. This
can be useful for account discovery (
which can be used to allow users to choose which account they would like
to use. The index of the preferred account can then be provided to a new
device via the
accountIndex attribute, and this device can be given to
LedgerProvider via its
For example, here is how you might get a list of account addresses on the device:
;const device = ;const accounts = await device;
Let's say the user has selected the account at index
3. To use that account,
you would then construct the provider as follows:
;;;// Simple formconst eth = accountIndex: 3 ;// Advanced form (equivalent result to the simple form above)const eth =device: accountIndex: 3;
Code of Conduct
This library is licensed under the MIT license.