Ok so my issue is that my website is hosted using a 3rd party service so I am unable to run geth on the same server as my site. However, I also have a separate VPS which I can setup nodejs and a web3js page or geth to interact with my contracts.

My goal is to call a constant function in my contract and display the result on my website. Is there a way for me to interact with my VPS from my website and call constant functions? Is there a better way to solve my issue?

If I run a node on my vps, am I able to use web3js on my site to call functions? What about transactions?


Run a Parity or Geth node hosted somewhere on the internet and expose the JSON-RPC interface to the internet (HTTP port 8545). Make sure this node does not have any keys attached to it, you won't need them for your usage.

From your website, you'll want to do an HTTP post over the JSON-RPC to the eth_call method. You can see the curl example at that link for details on how to structure the call.

Rather than trying to manually construct the parameters however, I recommend you use a helper library like web3, ethjs, or parity.js. You can see a full example of how to call a constant function in the ethjs documentation if you choose to go that route. Just change the ABI to match your method's ABI (you can get this from a tool like remix or Solidity compiler output) and change the HTTP address to that of your node.

  • How do I make sure there are now keys attached to the node? – JasonB Aug 1 '17 at 12:39
  • If it is a new node then it won't have any keys. Just make sure not to add any and you'll be fine. :). If you do add keys, you can remove them (differs by client). – Micah Zoltu Aug 1 '17 at 13:15
  • Ok, one last question. If I wanted to call a transaction rather than a constant, I would need keys. Is there a secure way to do this? Such that users of my site wont be able to access my keys / call transactions? – JasonB Aug 1 '17 at 13:26
  • You can sign a transaction on a server you control (securing your keys in whatever way makes sense to you) and then send that transaction to your public node. The act of signing a transaction and submitting a transaction to the blockchain can be separate actions, doing them at the same time using keys stored in the node is merely a convenience. To do this you will want to use github.com/paritytech/parity/wiki/… after you have signed the transaction on your secured server. – Micah Zoltu Aug 1 '17 at 14:22

Not sure if this is what you're looking for, and it is most certainly not a decentralized solution, but you might want to look into a service called Infura. It provides access to a node's RPC interface and does so at a very high level of availability. It's totally centralized, but that's a different issue.

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.