16

I have created my private Ethereum blockchain network. From different servers I am able to connected and added into the network as peer without any problem.

The way I run my server:

geth --targetgaslimit "994712388" --port 3000 --networkid 23422 --identity node1 
--verbosity 3 --nodiscover --nat none --datadir="/home/miner/MyEthereumEbloc" 
--rpccorsdomain '*' --rpc --rpcaddr "localhost" --
rpcport="8545" --nodiscover --maxpeers=6 --ipcapi "admin,eth,web3" --autodag

As you can see the RPC port is open:

$ telnet localhost 8545
Trying 127.0.0.1...
Connected to localhost.

Inside my geth console:

> admin.startRPC("127.0.0.1", 8545, "*", "web3,net,eth")
HTTP RPC already running on localhost:8545

http://localhost:8545 is the RPC port of my locally running Ethereum node software. But on my browser at http://localhost:8545 I am seeing the following error:

{"jsonrpc":"2.0","error":{"code":-32600,"message":"eof"}}

Inside the geth console, where I run my bootstrap node; I am running the following code in order to communicate to my local node:

var Web3 = require("web3");
var web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545'));
web3.isConnected()   //returns false

But web3.isConnected() keeps return false.

[Q] I know there is many documentation related to web3 connection to the local node and I have followed all the suggestions. But I am not able the fix the web3 connection problem I am facing. How could I fix this problem? Thank you for your valuable time and help.

I have done the suggestions from following questions: How to connect a web site to a geth node?, https://forum.ethereum.org/discussion/3414/step-by-step-guide-to-connect-a-web-site-to-a-geth-node, https://gitter.im/ethereum/web3.js/archives/2015/12/31.

4 Answers 4

8

EDIT: For other users reading this: The solution is to find in the comments of this answer - launching parameters were wrong.

http requests to the node are not supposed to return anything of use, it's totally fine that you get that response in your browser. Assuming you want to develop a dApp for your private chain, i recommend using https://github.com/ConsenSys/truffle - you tell truffle to communicate with your node, and then it handles all the communication between your website and your private chain. the documentation is really useful: https://truffle.readthedocs.io/en/latest/

Have fun ! :)

5
  • 1
    thanks @Nikita: Actually I have to use it for "EthExplorer "(github.com/etherparty/explorer).
    – alper
    Commented Nov 10, 2016 at 20:02
  • 1
    Ahh, there we have it - the port number! The description seems to be a little confusing, too, but from what I can tell here: you tried calling the port number of the geth RPC (8545), whereas the script requires you to open the browser in localhost:8000 . Did that work?
    – n1cK
    Commented Nov 10, 2016 at 22:23
  • 3
    via 8545, you contact only your geth node. via 8000, you contact the web server, serving you the app, which communicates with your geth node via rpc.
    – n1cK
    Commented Nov 11, 2016 at 12:32
  • 1
    After I have run "npm start" inside /explorer folder => localhost:8000 worked. But still web3.isConnected() returns me false that I was not able to fix it.
    – alper
    Commented Nov 12, 2016 at 1:50
  • 7
    I see some mistakes in your launch command. Change the RPC part to the following format: --rpc --rpcport 8545 --rpcaddr 0.0.0.0 --rpccorsdomain "*" --rpcapi "eth,web3" and replace everything according to your values. you have an unneccessary --rpccorsdomain '*' before --rpc, which is also spelled wrong.
    – n1cK
    Commented Nov 13, 2016 at 22:59
5

My problem is: I was trying to run all web3 commands inside geth console, where I should have used nodejs with the web3 library.

I have created file name: script.js:

var Web3 = require('./node_modules/web3/index.js');
var web3 = new Web3();
web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545'));

if(!web3.isConnected())
    console.log("not connected");
else
    console.log("connected");

On my terminal when I run: nodejs script.js it gives the output as connected.

2

Based on this thread - https://github.com/ethereum/remix/issues/588, I have tried following:

geth --datadir ./bc-data --networkid 9001 --nodiscover --rpc --rpccorsdomain "*" --unlock 0

After this remix could connect to - http://localhost:8545

0

I think the problem is that you've only enabled --ipcapi. You should enable --rpcapi along with select which options you want like admin eth and web3. Hope it solved it.

For example: geth --rpcapi eth,web3 --rpc

Enables the admin, official DApp and miner API over the IPC interface
Enables the official DApp and web3 API over the HTTP interface

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.