I have setup a local private test net and now I want to connect from Node.js to a node in the testned using IPC. I started a node with this command:

./geth --identity "5"  --datadir /home/davide/Documents/Ether/5th/ --networkid 4999 --port 30600 --nodiscover --ipcpath /home/davide/Documents/Ether/5th/geth.ipc --shh

This is my node.js scrypt

const http = require('http');
var fs = require('fs');
var net = require('net');

var Web3 = require('web3');

var web3 = new Web3(new Web3.providers.IpcProvider('/home/davide/Documents/Ether/5th/geth.ipc', net)); 


const hostname = '';
const port = 3000;

const server = http.createServer((req, res) => {
   res.statusCode = 200;
   res.setHeader('Content-Type', 'text/plain');
   res.end(web3.version+' '+console.log(web3.currentProvider)+' '+console.log(web3.eth.accounts)+' '+web3.contentProvider);


server.listen(port, hostname, () => {
   console.log(`Server running at http://${hostname}:${port}/`+web3.eth.accounts[0]);

and on the web page I get the following output:

1.0.0-beta.33 undefined undefined undefined

If I try to connect through geth attach everything works but with node.js it doesn't. What is the problem?


You are using console.log in the server callback, this will echo in the node console not in your html output.

In web3 v1.0 web3.eth.accounts is an object, not an array like in previous versions. Also web3 v1.0 only support async methods.

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.