We use Go and XRPL websocket APIs a lot a XRPScan. Unfortunately, the state of
the Go client libraries for XRPL at the time of publishing this package is not
ideal. This is where xrpl-go
comes in. It provides a low level API for interacting
with XRPL websocket interface. This
library aims to mirror concepts of the official JavaScript/TypeScript library
xrpl.js.
See the full reference documentation for all packages, functions and constants.
- Sending requests to observe ledger state using public websocket API methods
- Subscribing to changes in the ledger (ledger, transactions, validations streams)
- Parsing ledger data into mode convenient formats [WIP]
xrpl-go
is currently tested with rippled versions > 1.9.4. While it should
also be compatible with later versions, newer features available on XRPL mainnet
may not be available on day 0.
go get -u github.com/xrpscan/xrpl-go
Here are some examples showing typical use:
config := xrpl.ClientConfig{
URL: "wss://s.altnet.rippletest.net:51233",
}
client, _ := xrpl.NewClient(config)
err := client.Ping([]byte("PING"))
if err != nil {
panic(err)
}
request := xrpl.BaseRequest{
"command": "account_info",
"account": "rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe",
"ledger_index": "validated",
}
response, err := client.Request(request)
if err != nil {
fmt.Println(err)
}
fmt.Println(response)
client.Subscribe([]string{
xrpl.StreamTypeLedger,
})
for {
ledger := <-client.StreamLedger
fmt.Println(string(ledger))
}
client.Subscribe([]string{
xrpl.StreamTypeLedger,
xrpl.StreamTypeTransaction,
xrpl.StreamTypeValidations,
})
for {
select {
case ledger := <-client.StreamLedger:
fmt.Println(string(ledger))
case transaction := <-client.StreamTransaction:
fmt.Println(string(transaction))
case validation := <-client.StreamValidation:
fmt.Println(string(validation))
}
}
xrpl-go
is a work in progress. If you discover a bug or come across erratic
behavior, please create an issue
and we'll do our best to address it.