All requests routed to submodule when changing its provider in web3js

by lash   Last Updated August 01, 2020 13:28 PM

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) {
    console.debug(o);
});

let provider_b = new Web3.providers.IpcProvider('/tmp/foo.ipc', net);
w3.eth.personal.setProvider(provider_b);
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) {
    console.debug(o);
});

The output of the above is 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
0

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

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

I tried using two websocket providers, that does work.

However, I would assume that having a signer on an ipc connection while state and wire on ws would be an obvious use-case? Am I to understand that this is not posssible?



Related Questions






Websocket provider reconnects every 1 minute

Updated May 20, 2020 12:28 PM