Skip to content
This repository was archived by the owner on Apr 22, 2024. It is now read-only.

Hi @twt--, #376

Closed
Bow0628 opened this issue Jul 3, 2021 · 1 comment
Closed

Hi @twt--, #376

Bow0628 opened this issue Jul 3, 2021 · 1 comment

Comments

@Bow0628
Copy link

Bow0628 commented Jul 3, 2021

Hi @twt--,

I managed to make it work by using the following Provider:

const Web3 = require('web3');
const {LedgerSubprovider, Web3ProviderEngine } = require('@0x/subproviders');
const ProviderSubprovider = require('web3-provider-engine/subproviders/provider');
const Eth = require('@ledgerhq/hw-app-eth').default;
const TransportNodeHid = require('@ledgerhq/hw-transport-node-hid').default;

async function ledgerEthereumNodeJsClientFactoryAsync() {
    const ledgerConnection = await TransportNodeHid.create();
    const ledgerEthClient = new Eth(ledgerConnection);
    return ledgerEthClient;
}

class LedgerProvider extends Web3ProviderEngine {
    constructor(options, url, headers, debug) {
        super();

        this.addProvider(new LedgerSubprovider({
            baseDerivationPath: options.derivationPath,
            networkId: options.networkId,
            accountFetchingConfigs: {
                shouldAskForOnDeviceConfirmation: true,
            },
            ledgerEthereumClientFactoryAsync: ledgerEthereumNodeJsClientFactoryAsync,
        }));

        const web3Provider = new Web3.providers.HttpProvider(url, {headers, keepAlive: false});
        web3Provider.sendAsync = web3Provider.send;
        this.addProvider(new ProviderSubprovider(web3Provider));

        this.start();
    }

    send(...args) {
        return this.sendAsync(...args);
    }

}

And by using the exact following versions (truffle version is important):

        "truffle": "5.0.18",
        "web3-provider-engine": "15.0.7",
        "@ledgerhq/hw-transport-node-hid": "5.13.1",
        "@ledgerhq/web3-subprovider": "5.14.0",
        "@ledgerhq/hw-app-eth": "5.14.0",
        "@0x/subproviders": "6.0.8"

Originally posted by @mortimr in #340 (comment)

@mcmire
Copy link
Contributor

mcmire commented Apr 29, 2022

I am not quite sure why this comment was extracted to another issue. Sorry but this seems spammy, so I'm inclined to close this. Let me know if you think otherwise.

@mcmire mcmire closed this as completed May 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants