Developer
Getting started with Voyager
View
Search articles

Getting started with Voyager

Cancoin

A Websocket and REST server for querying Libbitcoin Server. It is written in Elixir using the Cowboy HTTP Server and connects to Libbitcoin Server via a ZeroMQ C-Port process pool.

 

Configuration

All configuration takes place in the config/config.exs file. You must supply the libbitcoin server URI and optionally a heartbeat, block, and transaction subscription URIs. If a subscription URI is given then a single supervised connection will be automatically started for each available endpoint.

config :bitcoin_voyager,
  port: 9090,
  bind: '127.0.0.1',
  uri: "tcp://voyager-api.cancoin.co:9091",
  heartbeat_uri: "tcp://voyager-api.cancoin.co:9092",
  block_uri: "tcp://voyager-api.cancoin.co:9093",
  transaction_uri: "tcp://voyager-api.cancoin.co:9094",
  pool: [size: 4],
  pidfile: "/tmp/bitcoin_voyager.pid"
 

Getting Started

You must install Erlang R18+ and Elixir 1.2.0+

You must install also libbitcoin 3.0 and include it in your LD_LIBRARY_PATH when running. See libbitcoin-nif for more info.

wget https://raw.githubusercontent.com/libbitcoin/libbitcoin/master/install.sh
bash install.sh --prefix=/usr/local/libbitcoin-master
mix deps.get
LD_LIBRARY_PATH=/usr/local/libbitcoin-master/lib mix test
 

Building a Release

To make a release run the following commands

MIX_ENV=prod mix compile
MIX_ENV=prod mix release
LD_LIBRARY_PATH=/usr/local/libbitcoin-master/lib ./rel/bitcoin_voyager/bin/bitcoin_voyager start
./rel/bitcoin_voyager/bin/bitcoin_voyager stop
 

REST API

All requests are over standard HTTP with no rate limiting and api keys required.

➜ curl https://voyager.cancoin.co/api/v1/blockchain/last_height
{"height":418101}
 

Websocket API

The websocket api uses a serialization format simmilar to libbitcoin server ZMQ requests. All requests must contain a semi-random unique ID, a command, and a set of parameters for the command.

Example querying for the latest known block height from javascript:

function id() {
  return Math.floor(Math.random() * 4294967296)
}

var websocket = new WebSocket("wss://voyager.cancoin.co/api/v1/websocket")

websocket.onmessage = function(event) {
  var message = JSON.parse(event.data)
  console.log(message.result)
}

websocket.onopen = function(event) {
  var request = JSON.stringify({
    id: id(),
    command: "blockchain.last_height",
    params: {}
  })

  websocket.send(request)
}
 

The response will include the ID that was sent with the request along with an result or an error value.

{id: id(), error: }
{id: id(), result: }
 

For more information and a full list of commands, visit the Voyager Github Repository.