Website to Geth Node – How to connect a website to a geth node

dappsgo-ethereumweb3js

Before the DApp-browser Mist was available, this web3 library seems the way to go on building a bridge from contract to a frontend (web site).

But, I cannot get the very basic examples to work.

These sources lack a few major points:

  1. What is the exact command to start geth to run the examples? I have used:

    geth --rpc console 2
    

    while mining etc.

  2. This example has the line:

    web3.setProvider(new web3.providers.HttpProvider());
    

    Should it be localhost?

    web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545'));
    
  3. Is there anyway to hide web3.setProvider and other JavaScript code from the page source viewable for the user? If the geth node address is public, that could be a security problem.

Maybe I'm asking obvious questions here, but it shouldn't be too much trouble to add at least the geth starting argument to the tutorials. The best case scenario would be to have step by step guide with no assumptions left blank.

Best Answer

For point number one, this should work:
geth --rpc --rpccorsdomain="*" console 2>> geth.log
Running --rpccorsdomain="*" is dangerous though, especially if you have unlocked accounts. Put your domain name instead of *. For localhost, add --rpcaddr="localhost"

Related Topic