2

I want to listen to events on a contract and then send them to a rest endpoint.

  1. Is it possible to make a REST call within the geth console?

  2. Alternatively, if I have a node application and I load web3, how can I connect to the testnet?

  • Consider making the answer as accepted, you can do it by checking the tick sign under votes. – niksmac Mar 25 '16 at 1:13
1

Yes, you can make REST calls from geth console specifically JavaScript Console of go-ethereum

As explained in the official how to

It is possible to specify the set of API's which are offered over an interface with the --${interface}api command line argument for the go ethereum daemon. Where ${interface} can be rpc for the http interface or ipc for an unix socket on unix or named pipe on Windows.

To determine which API's an interface provides the modules transaction can be used, e.g. over an ipc interface on unix systems:

echo '{"jsonrpc":"2.0","method":"modules","params":[],"id":1}' | nc -U $datadir/geth.ipc

connection to testnet is made by geth not the web3 interface. and web3 is used to any geth instance irrespective of whether is testate or live.

Read Connecting to the network

the method would be geth -—networkid="12345" console you can read more on the custom genesis block etc in the wiki.

  • So if I understand you correctly, in my geth client, if I've started it with jsonrpc for its communication to ethereum, that api is available to my own code running within geth to do my own calls to other non-ethereum rest servers? (I want to record contract events over a rest call to some other server) – James B Mar 12 '16 at 19:54
  • 1
    @JamesB There is no need to query other serve, your node is in sync with all other nodes, that is by design. – niksmac Mar 13 '16 at 1:34
  • I want to make a rest call (using javascript) to a different, non-ethereum service to record events from the blockchain (not to a different geth node) the code to listen to the event is in my local geth node and then calls externally to the blockchain over http – James B Mar 13 '16 at 8:54
  • 1
    You can use loadScript function of geth javascript console to load a regular javascript file to the console and execute functions. try that way. – niksmac Mar 13 '16 at 13:11
  • 1
    @JamesB Yeah, thats right. I was mistaken. including web3.js into your own html file or a node app will work fine. – niksmac Mar 14 '16 at 8:33

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.