0

I am trying to connect to a rinkeby full node in ubuntu terminal and i have a node js app deployed trying to connect using web3 when consoling the nodejs app getting connection error

  if (typeof web3 !== 'undefined') {
        web3 = new Web3(web3.currentProvider);
    } else {
        // set the provider you want from Web3.providers
        web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
    }


Error: CONNECTION ERROR: Couldn't connect to node http://localhost:8545.
    at Object.InvalidConnection (/var/www/ethernode/node_modules/web3/lib/web3/errors.js:31:16)
    at HttpProvider.send (/var/www/ethernode/node_modules/web3/lib/web3/httpprovider.js:93:18)
    at RequestManager.send (/var/www/ethernode/node_modules/web3/lib/web3/requestmanager.js:58:32)
    at Eth.get [as coinbase] (/var/www/ethernode/node_modules/web3/lib/web3/property.js:107:62)
    at app.get (/var/www/ethernode/app.js:37:29)
    at Layer.handle [as handle_request] (/var/www/ethernode/node_modules/express/lib/router/layer.js:95:5)
    at next (/var/www/ethernode/node_modules/express/lib/router/route.js:137:13)
    at Route.dispatch (/var/www/ethernode/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/var/www/ethernode/node_modules/express/lib/router/layer.js:95:5)
    at /var/www/ethernode/node_modules/express/lib/router/index.js:281:22

some one in stack overflow told to change the localhost to public Ip address , and that also didn't work , some one tell me what is happening here ?

2

Run the geth node on rinkeby testnet:

$ geth --rinkeby --ws --wsaddr 0.0.0.0 --wsport 8546 --wsorigins * --datadir /.rinkeby --cache 512 --rpc --rpcapi personal,eth,network --rpcaddr 0.0.0.0 --rpcport 8545 --fast --bootnodes enode://a24ac7c5484ef4ed0c5eb2d36620ba4e4aa13b8c84684e1b4aab0cebea2ae45cb4d375b77eab56516d34bfbd3c1a833fc51296ff084b770b94fb9028c4d25ccf@52.169.42.101:30303

make sure it's synced up:

$ geth attach ipc:/.rinkeby/geth.ipc
> eth.syncing
{
  currentBlock: 405371,
  highestBlock: 837461,
  knownStates: 272806,
  pulledStates: 269942,
  startingBlock: 271758
}

connect provider:

new Web3.providers.HttpProvider('http://localhost:8545')
| improve this answer | |
  • Just out of curiosity, how long is the sync supposed to take? – BelgoCanadian Jun 24 at 4:01
  • @BelgoCanadian it depends on your bandwidth, cpu, and disk i/o speed. I’ve seen it take hours to multiple days. – Miguel Mota Jun 24 at 15:13
0

'localhost' is your machine, therefore there is no rinkeby testnet there.

My suggestion is (and I did the same) to use public API like INFURA.

After registering and obtaining your token, you can connect to their endpoint like that:

web3 = new Web3(new Web3.providers.HttpProvider("https://rinkeby.infura.io/YOUR_TOKEN_HERE"));
| improve this answer | |
  • ok , i got it , my other doubt is if i connect , to infura will it support a wallet in my local machine can i do transactions from my wallet and is it secure , i read from a blog post that connecting to other nodes are not safe. thats why i tried to run a full node . on local machine – Shersha Fn Jan 21 '18 at 18:24
  • I followed your method but cannot connect to network – e.k Aug 27 '18 at 10:23

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.