6

I'm running a geth node on the testnet and trying to run web3.js method from my node server code.

Here's my code

var Web3 = require("web3");
var web3 = new Web3(new Web3.providers.HttpProvider('http://0.0.0.0:8545'));
console.log(web3.net.peerCount);

However, I'm getting net_peerCount method not implemented error.

Infact, I'm getting a similar method not implemented error when I try to access any net or eth methods.

Any help appreciated!

5

I got it working by running the command i found in the docs https://github.com/ethereum/go-ethereum/wiki/JavaScript-Console#adminstartrpc

admin.startRPC("127.0.0.1", 8545, "*", "web3,db,net,eth")

from my geth console!

Thanks for the suggestions :)

  • Could you please elaborate a bit about that command, maybe include a quote from the docs? Then you should mark it as answered. – Tjaden Hess Feb 10 '16 at 15:23
4

Try not to mix cases when you use the web3 variable. When you specify the address, I hope you didn't physically used 0.0.0.0. For a local node, here's an exampe:

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

For reference, consult the Javascript-API help document in the doc dir.

  • I needed to add a rpcdomain when starting geth in oder to get access. To allow access from all domains you can use: geth --rpc --rpccorsdomain="*" – digitaldonkey Mar 4 '16 at 19:17
3

This answer on reddit helped me.

Run geth with:

geth --rpc --rpcapi "web3,net,personal,eth"

The "personal" api is not exposed by default with the --rpc option. Once you do the above, it exposes all the ones listed, including personal which will allow you do do the personal_unlockAccount and personal_newAccount (which I'm assuming you are after).

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.