Check balance and send Ripple (XRP) using Java

Update: As mentioned in here, since rippled 1.1.0 remote sign API is not allowed by default anymore. If you try to call it on wss://s.altnet.rippletest.net:51233 you will get “Signing is not supported by this server” error. Check this post on how to sign transaction locally using Java

Ripple (XRP) provides some options to interact with their currency/coin. One of the most recommended way is by using their official node.js package, ripple-lib as suggested in their doc. But let say, for some reason we don’t want to use node.js, then one of the best option is using their websocket API which are well-documented (as expected from “company-maintained” blockchain 😜). In this post I will show how I do it with Java (yes, this is only one of many possible ways).

Ripple websocket API is publicly available and does not required registration or token to access it

Initially, I want to use ripple-lib-java (official but not really maintained) to handle everything. But unfortunately, due to lack of documentation (and maybe my laziness), I didn’t manage to find how. So I only use it to handle the cryptographic parts and use Java-WebSocket to directly communicate with their test/sandbox API at wss://s.altnet.rippletest.net:51233.

Since I want to have each processes work sequentially, I make a simple blocking/synchronous websocket client implementation:

For an XRP address (Account ID) to be valid, it is not only need to be generated with proper cryptographics but also need to have a certain minimum balance (XRP 20 as per February 2018) as explained here. If you try to check balance of an empty account ID using above API, it will throw an invalid error.