0

I installed Ropsten (revival) testnet on an Ubuntu server, Then I start my testnet node:

geth --testnet

I can connect to my node via

geth attach ipc:/home/myusername/.ethereum/testnet/geth.ipc

and I get this info from my node instance:

> admin.nodeInfo
{
  enode: "enode://03aa54...0689be3@24.230.213.120:30303",
  id: "03aa54b894aec...a49d8490689be3",
  ip: "www.xxx.yyy.zzz",
  listenAddr: "[::]:30303",
  name: "Geth/v1.6.7-stable-ab5646c5/linux-amd64/go1.8.1",
  ports: {
    discovery: 30303,
    listener: 30303
  },
  protocols: {
    eth: {
      difficulty: 1621387497788667,
      genesis: "0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d",
      head: "0x84e8e85cdd7a5fa79d26b9fa89cd850be23b13d2079208e052eceb06c436654b",
      network: 3
    }
  }
}

But I cannot connect to the testnet node from my nodejs script:

Web3 = require("web3");
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:30303"));
console.log(web3.isConnected());

always return false ! Any advice ?

3

The port 30303 is used by the client (TCP as listener and UDP for discovery) to communicate in the peer to peer protocol.

For Web3, you must use the JSON-RPC port (by default 8545) which can be enabled with the following parameter --rpc

Command:

geth --testnet --rpc --rpcapi "eth,net,web3" --rpccorsdomain '*' --rpcaddr 127.0.0.1 --rpcport 8545 

Then you can try to run:

Web3 = require("web3");
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
console.log(web3.isConnected());

More details

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.