2

I'm hosting a Django website on an Apache virtual machine and wanted to connect it Ethereum. Currently, the page I'm working on is hosted at

146.169.45.149:9002

Since I wanted to run a node at that address so I could connect the two, I ran this to start geth

geth --genesis customGenesis.json --rpc --rpcaddr "146.169.45.149" --rpcport "9002" --datadir testchain --nodiscover --networkid 1234 console

However, this isn't working and I'm getting the following error

Fatal: Error starting RPC: listen tcp 146.169.45.149:9002: bind: address already in use

Everything else seems to be working but the code is this

<!------- SCRIPT------------------>
<script type="text/javascript">
    var Web3 = require('web3');
    var web3 = new Web3();
    web3.setProvider(new web3.providers.HttpProvider("146.169.45.149:9002"));
    var mining = web3.eth.mining;
    document.getElementById("Mining").innerText = mining;
</script>

</body>

I'm new at this so it could be something related to rpc but I couldn't figure it out from what I read.

3

I managed to make it work by running geth --genesis customGenesis.json --rpc --rpcport "9012" --rpcaddr "0.0.0.0" --rpccorsdomain "*" --datadir testchain --networkid 1234 console

From what I understood, this works but it's less secure. I would like to find a safer way of doing it.

Also, I had to change something in the script part which is now

<!------- SCRIPT------------------>
<script type="text/javascript">

  var Web3 = require('web3');

  var web3 = new Web3();

    web3.setProvider(new web3.providers.HttpProvider("http://146.169.45.149:9012"));
    var mining = web3.eth.mining;
    document.getElementById("Mining").innerText = web3.eth.accounts[0];
</script>

</body>
2

You cannot run more than one program to listen and serve on a single port on the same computer:

If you want to serve your Apache web page on the port 9002, choose another port for geth to serve it's RPC requests on.

For example, use port 9001 for geth RPC:

geth --genesis customGenesis.json                   \
  --rpc --rpcaddr "146.169.45.149" --rpcport "9001" \
  --datadir testchain --nodiscover --networkid 1234 console

And in your script, use:

<!------- SCRIPT------------------>
<script type="text/javascript">
    var Web3 = require('web3');
    var web3 = new Web3();
    web3.setProvider(new web3.providers.HttpProvider("146.169.45.149:9001"));
    var mining = web3.eth.mining;
    document.getElementById("Mining").innerText = mining;
</script>


  • I tried doing that (changing the port on both the geth command and the setProvider statement) but it didn't work. I get a warning "Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help xhr.spec.whatwg.org" and an error POST XHR http://146.169.45.149:9002/your_council/146.169.45.149:9012 [HTTP/1.0 404 Not Found 29ms – punddalinni May 8 '16 at 15:26
  • You probably need to set --rpccorsdomain – Edmund Edgar May 8 '16 at 23:44
  • I tried with with geth --genesis customGenesis.json --rpc --rpcaddr "146.169.45.149" --rpcport "9012" --rpccorsdomain "*" --datadir testchain --networkid 1234 console but it still doesn't work. The error is "XMLHttpRequest cannot load %3146.169.45.149:9012. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource" and "Uncaught Error: CONNECTION ERROR: Couldn't connect to node 146.169.45.149:9012" – punddalinni May 9 '16 at 9:32

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.