Wracking my brains here, geth is running the RPC as expected but I can't connect to it with web3 I'm running like so:

geth --rpc --rpccorsdomain "*" --rpcapi "eth,web3"

I'm running this in screen and see in the terminal it starts running the RPC API and then continues to sync the blockchain.

I have confirmed the API is running:

curl -H "Content-Type: application/json" -X POST --data '{"jsonrpc":"2.0","method":"web3_clientVersion","params":[],"id":67}' http://localhost:8545

Which returns as expected:


I'm running nodejs v6.12.3 and npm install web3 this morning. The nodejs script I'm trying is:


var Web3 = require('web3');
var web3 = new Web3(); // returns as expected

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

var coinbase = web3.eth.coinbase;
console.log(coinbase); // undefined

I noticed that after running setProvider inspecting the web3 object I see:

_provider: HttpProvider { host: 'http://localhost:8545', timeout: 0, connected: false },

I've tried a number of other web3.eth API's but no luck. How can I get it connected? Have I fundamentally misunderstood something here?


npm installs the new version of the API by default now. You can check with:

var Web3 = require('web3');
var web3 = new Web3();

If it's >1.0.0 you need to refer to this documentation: http://web3js.readthedocs.io/en/1.0/index.html

Or get the old version:

npm uninstall web3
npm install web3@0.20.3

I should not be allowed around computers.

  • 1
    this does not answer the question at all
    – lasec0203
    Mar 19 at 3:45

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.