0

I have setup my own private eth network. I wanted to connect to this. So first I have run

geth --datadir ./tolotolo --networkid 1115 --port 30304 console 2>>myEth.log

It generated geth.ipc file. Then I do

geth --ipcpath tolotolo/geth.ipc --networkid 1167 --port="56789"

Then in my node js I have installed web3 then I tried to connect

var Web3 = require('web3');
var web3 = new Web3("ws://192.168.1.99:56789");
web3.eth.net.isListening()
    .then(() => console.log('is connected'))
    .catch(e => console.log(e));

It produced output

Error: connection not open on send()
    at Object.ConnectionError (C:\Users\karthik.KT\workspace\tolotolo\server\node_modules\web3-core-helpers\src\errors.js:69:23)
    at Object.ConnectionNotOpenError (C:\Users\karthik.KT\workspace\tolotolo\server\node_modules\web3-core-helpers\src\errors.js:48:21)
    at C:\Users\karthik.KT\workspace\tolotolo\server\node_modules\web3-providers-ws\src\index.js:181:37
    at Map.forEach (<anonymous>)
    at WebsocketProvider._onClose (C:\Users\karthik.KT\workspace\tolotolo\server\node_modules\web3-providers-ws\src\index.js:180:27)
    at W3CWebSocket._dispatchEvent [as dispatchEvent] (C:\Users\karthik.KT\workspace\tolotolo\server\node_modules\yaeti\lib\EventTarget.js:115:12)
    at W3CWebSocket.onConnectFailed (C:\Users\karthik.KT\workspace\tolotolo\server\node_modules\@web3-js\websocket\lib\W3CWebSocket.js:219:14)
    at WebSocketClient.<anonymous> (C:\Users\karthik.KT\workspace\tolotolo\server\node_modules\@web3-js\websocket\lib\W3CWebSocket.js:59:25)
    at WebSocketClient.emit (events.js:223:5)
    at ClientRequest.handleRequestError (C:\Users\karthik.KT\workspace\tolotolo\server\node_modules\@web3-js\websocket\lib\WebSocketClient.js:227:14)
    at ClientRequest.emit (events.js:223:5)
    at Socket.socketOnEnd (_http_client.js:440:9)
    at Socket.emit (events.js:228:7)
    at endReadableNT (_stream_readable.js:1185:12)
    at processTicksAndRejections (internal/process/task_queues.js:81:21) {
  code: 1006,
  reason: 'connection failed'
}

What is the best way to connect to my private network using web3? Thank you.web3

3
  • Try web3 = new Web3(new Web3.providers.HttpProvider("http://192.168.1.99:56789")); – Niklas Feurstein May 22 '20 at 9:01
  • Http provider works but I want to connect via ipc since it is more secure – e.k May 22 '20 at 10:41
  • You are running a recent version of web3 right? Cause I remember there being a bug with websockets – Niklas Feurstein May 22 '20 at 11:02
0

Maybe it works with this code:

var Web3 = require('web3');
const provider = new Web3.providers.WebsocketProvider("ws://192.168.1.99:56789")
var web3 = new Web3(provider);
web3.eth.net.isListening()
    .then(() => console.log('is connected'))
    .catch(e => console.log(e));

You should probably also make sure that there is no firewall issue

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.