How can I interact with a remote node using web3.js?

kostaskostas Member Posts: 16
As is clear from the documentation, web3.js is meant to control a local node.

If I wanted to remote a control node, am I looking at hacking web3.js or geth?

It seems that I can achieve remote control if I do admin.startRPC("0.0.0.0", "port-goes-here") but I'm not sure that's the right way to go about it.

Thank you.

Comments

  • tomgalvintomgalvin Member Posts: 10
    I could be wrong on this, but I believe that controlling a remote node (i.e. going over the internet or some other untrusted network) is currently dangerous, as the RPC calls are not encrypted, so anyone can control the node and so send transactions and steal funds, etc. So at this point, it's only safe to connect to a local node.
  • kvhnukekvhnuke Member Posts: 15
    edited June 2015
    you dont have to hack anything, run geth with
    geth --rpc --rpcaddr "0.0.0.0" --rpcport port--rpccorsdomain "*" console or you can strart rpc with admin.startRPC("0.0.0.0", "port-goes-here", "*") (dont forget the * thats the trick which will allow outside domains to connect to your node)
    then initialize web3 as follows
    var web3 = require('web3'); web3.setProvider(new web3.providers.HttpProvider('http://ip:port/'));
  • kostaskostas Member Posts: 16
    Thank you both for the reply.

    @kvhnuke: that's what I ended up doing!
  • PranayPranay Member Posts: 58
    Its simple, we just need to give the proper url for http provider to initialize the remote connection with web3.
Sign In or Register to comment.