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?