Using web3.js 1.2.11, I expect the last part of the following code to route requests from the web3.eth.personal module to the IPC socket, and requests on web3.eth to TCP port 7545.

let Web3 = require('web3');
let net = require('net');

let provider_a = new Web3.providers.WebsocketProvider('ws://localhost:7545');
let w3 = new Web3(provider_a);
console.debug('root', w3.currentProvider.url);
console.debug('personal', w3.eth.personal.currentProvider.url);
w3.eth.getBlockNumber().then(function(o) {

let provider_b = new Web3.providers.IpcProvider('/tmp/foo.ipc', net);
console.debug('root', w3.currentProvider.url, w3.currentProvider.path);
console.debug('personal', w3.eth.personal.currentProvider.url, w3.eth.personal.currentProvider.path);
w3.eth.getBlockNumber().then(function(o) {

The output of the above, using an actual provider on 7545 and socat UNIX-LISTEN:/tmp/foo.ipc -, outputs:

root ws://localhost:7545
personal ws://localhost:7545
root ws://localhost:7545 undefined
personal undefined /tmp/foo.ipc

More precisely, the second getBlockNumber() call shows up on the unix socket.

I tried using two websocket providers, this works in some cases (web3.eth.getBalance), not in others (web3.eth.Contract.methods...call..)

I tried using two http providers, same problem (but afaiu this is deprecated anyway).

Am I to understand that combining provider types is not possible?

Your Answer

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

Browse other questions tagged or ask your own question.