0

I have a geth node launch on linux, I want to access it through the IPC connection in a Node.js application.

I am getting this error :

/home/**/node_modules/web3-core-helpers/lib/errors.js:66
        const error = new Error(msg);
                      ^

Error: CONNECTION ERROR: Couldn't connect to node on IPC.
    at Object.ConnectionError (/home/**/node_modules/web3-core-helpers/lib/errors.js:66:23)
    at Object.InvalidConnection (/home/**/node_modules/web3-core-helpers/lib/errors.js:36:21)
    at IpcProvider._timeout (/home/**/node_modules/web3-providers-ipc/lib/index.js:158:48)
    at Socket.<anonymous> (/home/**/node_modules/web3-providers-ipc/lib/index.js:86:15)
    at Socket.emit (node:events:390:22)
    at emitErrorNT (node:internal/streams/destroy:188:8)
    at emitErrorCloseNT (node:internal/streams/destroy:153:3)
    at processTicksAndRejections (node:internal/process/task_queues:81:21)
npm ERR! code 1
npm ERR! path /**
npm ERR! command failed
npm ERR! command sh -c node app.js

npm ERR! A complete log of this run can be found in:
npm ERR!     /**/.npm/_logs/2021-03-02T19_17_41_336Z-debug.log

I run geth like this : geth --datadir /mnt/ssd/ethereum --syncmode fast --cache 256 --ipcpath /**/ethereum/geth.ipc --ropsten

geth attach work well with the IPC and WebSocket connection, and the node is fully synchronized

I tried by enabling the WebSocket connection and everything works, only the IPC connection doesn't work on the Node.js app :/

geth version : 1.9.25-stable-e7872729

Node.js version : v15.10.0

Edit 1 :

This is how i connect my Node.js app using web3. The following script work with the WebSocket connection but not with the IPC connection (i get the mentioned error) :

const net = require('net');
const Web3 = require('web3');
const web3 = new Web3(new Web3.providers.IpcProvider("ipc://home/**/geth.ipc", net));
//const web3 = new Web3(new Web3.providers.WebsocketProvider("ws://127.0.0.1:8546"));
web3.eth.getBalance("0x0000000000000000000000000000000000000000").then(console.log);

If it's work with WebSocket, is not from Geth & the IPC connection work with geth attach so it's definitely not a Geth issue.

File permission issue ..? I tried sudo chown -R my_username:my_username on my Node.js app directory but i got the same error.

Edit Solved!

Check this dumb error... When you want to connect via IPC with Web3 you need to specify the path only, without the protocol :

Not Correct :

const web3 = new Web3(new Web3.providers.IpcProvider("ipc://home/**/geth.ipc", net));

Correct :

const web3 = new Web3(new Web3.providers.IpcProvider("/home/**/geth.ipc", net));

2
  • How do you connect with ipc? – Ismael Mar 3 at 5:03
  • @Ismael Like this : const net = require('net'); const Web3 = require('web3'); const web3 = new Web3(new Web3.providers.IpcProvider("ipc://home/**/geth.ipc", net)); If i run my node.js app with this, it's good, no error. But when i try to interact with the blockchain (ex: get the balance of an account) this gives the error. And with the Websocket connection, my app work perfectly. I connect like this : const web3 = new Web3(new Web3.providers.WebsocketProvider("ws://127.0.0.1:8546")); – Max Mar 3 at 11:25

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.