0

I am developing a simple Voting dApp by following a tutorial. In this tutorial we are using npm install ethereumjs-testrpc web3 so that we can get the fake nodes of Ethereum.

For that i first created the object of web3 by using Web3 = require('web3') command in the Node.js command prob. After using the command i should get all the attributes of Web3. But i am only getting [Function: Web3].

After that i am using web3 to connect to the localhot:8545 by using web3 = new Web3("http://localhost:8545") in the Node.js command prob. To check that i am connected to localhost:8485 i am using web3.eth.getAccounts(console.log). I should get addresses as follows;

['0x9c02f5c68e02390a3ab81f63341edc1ba5dbb39e',
'0x7d920be073e92a590dc47e4ccea2f28db3f218cc',
'0xf8a9c7c65c4d1c0c21b06c06ee5da80bd8f074a9',
'0x9d8ee8c3d4f8b1e08803da274bdaff80c2204fc6',
'0x26bb5d139aa7bdb1380af0e1e8f98147ef4c406a',
'0x622e557aad13c36459fac83240f25ae91882127c',
'0xbf8b1630d5640e272f33653e83092ce33d302fd2',
'0xe37a3157cb3081ea7a96ba9f9e942c72cf7ad87b',
'0x175dae81345f36775db285d368f0b1d49f61b2f8',
'0xc26bda5f3370bdd46e7c84bdb909aead4d8f35f3']

All i need is one of those addresses to proceed further. But i am getting an error which says that Connection refused or URL couldn't be resolved as follows;

Promise {
  <pending>,
  domain:
   Domain {
     domain: null,
     _events:
      [Object: null prototype] {
        removeListener: [Function: updateExceptionCapture],
        newListener: [Function: updateExceptionCapture],
        error: [Function: debugDomainError] },
     _eventsCount: 3,
     _maxListeners: undefined,
     members: [],
     [Symbol(kWeak)]: WeakReference {} } }
> Error: Connection refused or URL couldn't be resolved: http://localhost:8545
    at XMLHttpRequest.request.onreadystatechange (D:\Notes\BCS\Semester 7\FYP\New One\node_modules\web3-providers\dist\web3-providers.cjs.js:759:22)
    at XMLHttpRequestEventTarget.dispatchEvent (D:\Notes\BCS\Semester 7\FYP\New One\node_modules\xhr2-cookies\dist\xml-http-request-event-target.js:34:22)
    at XMLHttpRequest._setReadyState (D:\Notes\BCS\Semester 7\FYP\New One\node_modules\xhr2-cookies\dist\xml-http-request.js:208:14)
    at XMLHttpRequest._onHttpRequestError (D:\Notes\BCS\Semester 7\FYP\New One\node_modules\xhr2-cookies\dist\xml-http-request.js:349:14)
    at ClientRequest.<anonymous> (D:\Notes\BCS\Semester 7\FYP\New One\node_modules\xhr2-cookies\dist\xml-http-request.js:252:61)
    at ClientRequest.emit (events.js:198:13)
    at ClientRequest.EventEmitter.emit (domain.js:448:20)
    at Socket.socketErrorListener (_http_client.js:392:9)
    at Socket.emit (events.js:198:13)
    at Socket.EventEmitter.emit (domain.js:448:20) null

I also check a relevant answer to my question in this stack exchange. But this answer is telling to use truffle instead of solving the above problem. And if comments of this answer are solving the above problem then they are perhaps solving it for actual web3 not for ethereumjs-testrpc web3.

I am using solidity and if you need the code i can edit my question.

9
  • Are you referring to the latest version of the tutorial? The latest version edited in Fed 2019 seems to use ganache-cli which is what testrpc is known as now. Even if you installed using npm install, you have to bring up the test RPC node before you can connect to that node.
    – Sanjay S B
    Jun 9, 2019 at 3:54
  • i used how i can bring up the test RPC node before you can connect to that node ? Jun 9, 2019 at 5:29
  • 2
    If you are using ganache, enter ganache-cli in another terminal and keep it running
    – Sanjay S B
    Jun 9, 2019 at 6:28
  • yes thank you, i just figured it out. Jun 9, 2019 at 6:29
  • Assuming you used npm install -g ganache-cli to install
    – Sanjay S B
    Jun 9, 2019 at 6:30

1 Answer 1

0

Try this,

  1. Open a new terminal and move to the folder chapter1 (following the tutorial).
  2. In the terminal run this node_modules/.bin/ganache-cli
  3. Open a new one terminal and test node, following the 2nd section of the tutorial.
  4. Don't close the terminal opened in the 1st step.

That works for me!

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.