3

For the past week I have been trying to make an app that runs on a node.js server to control the balance going out of different ethereum accounts / wallets. Here is what I have done so far:

(on my Ubuntu 16.04)
  • install the mist wallet

  • run the following command to install web3:

npm install web3

(already have npm and node.js installed)

  • create a simple javascript program to test out using the web3 library:

    var Web3 = require('web3');
    var web3 = new Web3(new Web3.providers.HttpProviders("http://localhost:8545"));  
    
    var version = web3.version.api;
    console.log("version: " + version);
    

and the output is:

version: 0.19.1

  • Now to add an extra line to the above script and see how web3 communicates with the wallet:

    var sender = web3.eth.accounts[0];
    console.log("sender = " + sender);
    

but the output gives me the following error:

/home/ubuntuuser/node_modules/web3/lib/web3/httpprovider.js:91
        throw errors.InvalidResponse(request.responseText);
        ^

Error: Invalid JSON RPC response: undefined
    at Object.module.exports.InvalidResponse (/home/ubuntuuser/node_modules/web3/lib/web3/errors.js:38:16)
    at HttpProvider.send (/home/ubuntuuser/node_modules/web3/lib/web3/httpprovider.js:91:22)
    at RequestManager.send (/home/ubuntuuser/node_modules/web3/lib/web3/requestmanager.js:58:32)
    at Eth.get [as accounts] (/home/ubuntuuser/node_modules/web3/lib/web3/property.js:107:62)
    at Object.<anonymous> (/home/ubuntuuser/Desktop/Ethereum/ethy.js:17:22)
    at Module._compile (module.js:410:26)
    at Object.Module._extensions..js (module.js:417:10)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Function.Module.runMain (module.js:442:10)

And I get the sa,me error when trying to use code like:

var ethVersion = web3.version.ethereum;

QUESTION: What might I be doing wrong? Is web3 unable to communicate with the wallet because something is missing?

2 Answers 2

2

By default the Mist wallet does not listen for RPC requests. If you want to use web3 to communicate with a client, you should install a command line client like geth or parity. These both have options to listen for RPC requests.

13
  • Oh interesting. I read somewhere that geth comes with Mist by default, though I'll have to look into it to make sure. Will look into it, test it out, and write back here with feedback.
    – Webeng
    Jul 1, 2017 at 15:52
  • It does, actually. Mist has a geth executable packaged with it that will work, but you need to call it from the command line with the --rpc flag. I find it's easier to install geth to somewhere on your path, though Jul 1, 2017 at 15:54
  • Oh nice. I'm now trying to find out how that works. I tried opening a terminal and typing geth --rpc though obviously didn't work, now looking online for documentation. How might I be able to do it?
    – Webeng
    Jul 1, 2017 at 16:22
  • What OS are you using? Jul 1, 2017 at 16:23
  • 1
    You should be able to run both if you do it in the opposite order. Run geth first, then Mist Jul 1, 2017 at 17:09
0

You don't need to use Mist. Just run geth from the terminal

geth --fast --cache=512 --testnet --rpc

Your Answer

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

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