Beginner in ethereum i started a private network using the following command

sudo geth --fast --cache 512 --ipcpath ~/Library/Ethereum/geth.ipc --networkid 1234 --rpcport "8081"  --datadir ~/.ethereum_private  console[![enter image description here][1]][1]

in my node js application

var Web3 = require('web3');

if (typeof web3 !== 'undefined') {
  web3 = new Web3(web3.currentProvider);
} else {
  // set the provider you want from Web3.providers
  web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));


web3.isConnected() return always false

1 Answer 1


In your command, you set RPC port to 8081 In your code, you try to connect to port 8545 So change web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545")); To web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8081"));

Moreover, with web3 1.0.0, the isConnected() method won't return true unless you already tried to connect to the node. It's still in beta, so you can't rely on this method yet.

  • changed the port but still the same false\,web3 version is 0.19.0 Commented Apr 3, 2018 at 6:56
  • When i changed the port name Invalid JSON RPC response: undefined Commented Apr 3, 2018 at 7:00
  • Add the "--rpc" flag to your command to launch geth Commented Apr 3, 2018 at 7:01
  • yeah its worked:) Commented Apr 3, 2018 at 7:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.