HTTP Bridge usage example

Here we demonstrate how you can implement the simplest possible GreenAddress client fetching a wallet balance via the HTTP Bridge which doesn’t require any WAMP capabilities from the client.

Requirements

To implement this example, we use just the curl command line HTTP client, but you can use any HTTP client or library of your choice.

NOTE: Experimental feature

Please note the HTTP Bridge is an experimental feature and may result in unexpected behaviour. Also there is one known issue (https://github.com/crossbario/crossbar/issues/604) with error handling, which causes the server to fail to send error statuses to requests that normally should result in failures.

Thus if you encounter timeouts, it can mean you are not receiving some error status - check your data.

Overview

To log in to a GreenAddress wallet using custom login, you need a the username and password to the watch_only() call. To retrieve wallet balance, you simply call get_balance().

Using the GreenAddress WAMP server

Retrieving a token and creating a session

To connect to GreenAddress server, you need to acquire a token over HTTP which is used for collecting usage data about issued requests:

$ curl https://greenaddress.it/token/

Store the returned value somewhere and then call :gait:meth`.create_session` to create a new GA session, replacing TOKEN below with your token value.:

$ curl -H "Content-Type: application/json" -d '{"procedure": "com.greenaddress.login.create_session", "args": ["TOKEN"]}' https://greenaddress.it/httpbridge/

Again store the returned value and use it in further calls to pass as session id.

Logging in and retrieving the balance

Now after retrieving the token and creating the session, you can log in using custom login, and retrieve the balance:

$ curl -H "Content-Type: application/json" -d '{"procedure": "com.greenaddress.login.watch_only", "kwargs": {"session_id": "[your session id]"}, "args": ["custom", {"username": "[your username]", "password": "[your password]"}, false]}' https://greenaddress.it/httpbridge/

$ curl -H "Content-Type: application/json" -d '{"procedure": "com.greenaddress.txs.get_balance", "kwargs": {"session_id": "[your session id]"}}' https://greenaddress.it/httpbridge/