Silkroad

A fast, thread-safe, simple, lightweight, batchable interface to the bitcoind JSON-RPC api. Uses HTTPClient for high performance.

Installation

Add this line to your application's Gemfile:

gem 'silkroad'

And then execute:

$ bundle

Or install it yourself as:

$ gem install silkroad

Usage

Initialize the client:

silkroad = Silkroad::Client.new 'rpcuser', 'rpcpass'

You can set a custom url:

silkroad = Silkroad::Client.new 'rpcuser', 'rpcpass', url: 'https://yourbitcoinddaemon.com:31337'

Now you can make RPC API calls (see the API calls list). Pass params as per the spec, and the result will be returned as an array or hash (depending on the call):

silkroad.rpc 'getbalance', '[email protected]' # => 31337

Errors throw the Silkroad::Client::Error exception. Catch it if you want to do something custom:

begin
  silkroad.rpc 'failcmd', 'fail'
rescue Silkroad::Client::Error => e
  puts "Error: #{e.inspect}"
end

Batching

If you use batching, it will throw all your requests into a JSON array, send them at once, and return all of them when they are done, per the JSON-RPC spec. Batch is much lower level, and does not raise exceptions on errors. You will need to look for the response[index]['error'] in the return and handle it.

response = @silkroad.batch do
  rpc 'getbalance', '[email protected]'
  rpc 'notworking', 'derp'
end

# response is:
[
  {result: 31337, error: nil, id: nil},
  {result: nil, error: {code: -32601, message: 'Method not found'}, id: nil}
]

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Winners Don't Use Drugs - William S. Sessions, Director, FBI