3

I am using truffle-hdwallet-provider to connect to the node that operates over https and it works perfectly. Now I want to connect to websocket-powered node but keep my HD Wallet provider. I cannot find how to do that. All I found is package web3-providers-ws but cannot find is it possible (and how) to chain multiple providers?

1

In https://github.com/trufflesuite/truffle-hdwallet-provider/blob/master/index.js, it is hard coded to use HttpProvider

You would need to fork and modify this line of code:

 this.engine.addProvider(new Web3Subprovider(new Web3.providers.HttpProvider(provider_url)));

to instead:

 this.engine.addProvider(new Web3Subprovider(new Web3.providers.WebsocketProvider(provider_url)));

I will give it a try some day and get back to this thread...

1

You can pass an instance of the provider instead of a string as a second argument. So you can pass a websocket provider in:

const webSocketProvider = new Web3.providers.WebsocketProvider(...);
const walletProvider = new HDWalletProvider(mnemonic, webSocketProvider);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.