Localhost 8545 – Understanding What It Is

corsjson-rpcnodes

Why do some ethereum related websites (for example regis.nu, there are many others) tell me they cannot find a node running at http://localhost:8545 and what can I do about that?

Regis.nu allowed me to create a "light-wallet" and then I had to put some ether in there, but I didn't really want to do that. I wanted to use my own wallet. I tried starting 'geth' but now I'm going into deep water and I can't swim.

So question: How can I start a node at http://localhost:8545?

Best Answer

http://localhost:8545 is the RPC port of your locally running Ethereum node software.

When running geth, the Go implementation of the Ethereum node software, the command line parameters to create and configure this RPC service follows:

user@Kumquat:~$ geth --help | grep rpc
  --rpc                         Enable the HTTP-RPC server
  --rpcaddr "127.0.0.1"         HTTP-RPC server listening interface
  --rpcport "8545"              HTTP-RPC server listening port
  --rpcapi "db,eth,net,web3"    API's offered over the HTTP-RPC interface
  --rpccorsdomain               Domains from which to accept cross origin requests (browser enforced)

The defaults for --rpcaddr, --rpcport and --rpcapi will allow the regis.nu webpage to connect to your local geth node. You will however need to configure the --rpccorsdomain to allow your web browser to get access to your local Ethereum node.

To start a node on your local machine providing the regis.nu webpage with access to your node, try:

geth --rpc --rpcaddr "127.0.0.1" --rpcport "8545" \
  --rpc --rpccorsdomain "http://regis.nu" console

Note: Setting --rpccorsdomain to "http://regis.nu" will work with the regis.nu webpage. If you are having trouble connecting, start testing with "*" to check whether the webpage can connect to your node, then find the correct setting to minimise your security risk - see Cross-origin resource sharing for more information. And note that using "*" could be risky.

Looking into the JavaScript code in regis.nu/main.js linked from regis.nu, you will see:

 module.exports={nodeAddress:["http://localhost:8545","http://104.41.138.167:8545"], ...}

The page will firstly try connecting to your RPC port locally, then try the RPC port available at IP address 104.41.138.167 .

I loaded http://regis.nu in my web browser, then clicked on the Start button, but the website could not connect to the RPC port of my locally running geth. I had to temporarily allow http://localhost in my NoScript addon within my browser before the regis.nu web page was allowed to connect to my local geth node and list my accounts.

Useful reference:

Related Topic