Asynchronous (EventMachine) JSON-RPC 2.0 client

This gem is a client implementation for JSON-RPC 2.0. It uses EventMachine to enable asynchronous communication with a JSON-RPC server. It can be used synchronously if called within a (non-root) fiber.

Usage example for asynchronous behaviour:

wallet      ='https://localhost:8332/') # Local bitcoin wallet
balance_rpc = wallet.getbalance()
balance_rpc.callback do |result|
  puts result # => 90.12345678

balance_rpc.errback do |error|
  puts error
  # => "JsonRpcClient.Error: Bad method, code: -32601, data: nil"

Usage example for synchronous behaviour:

require 'eventmachine'
require 'json-rpc-client'
require 'fiber' do
  # To use the syncing behaviour, use it in a fiber.
  fiber = do
    article =
      {asynchronous_calls: false}
    puts article.get({name: true})
    # => {:name=>{:sv=>"Presentkort 1000 kr", :en=>"Gift certificate 1000 SEK"}}




The client supports both a default logger (for all instances) and a per instance logger. Simply attach a logger of your choice(that responds to info, warning, error and debug) and any interaction will be output as debug, and any errors as errors. Any per instance logger will override the default logger for that instance.

require 'logger'
JsonRpcClient.default_logger =$STDOUT)
wallet ='https://localhost:8332/') # Local bitcoin wallet
wallet.logger =


To set up a development environment, simply do:

bundle install
bundle exec rake  # run the test suite

There are autotests located in the test folder and the framework used is Bacon. They're all mocked with VCR/Webmock so no internet connection is required to run them.


JSON-RPC 2.0 is a very simple protocol for remote procedure calls, agnostic of carrier (http, websocket, tcp, whatever…).

JSON-RPC 2.0 Specification


Copyright (C) 2012-2013, Textalk AB

JSON-RPC client is freely distributable under the terms of an MIT license. See LICENCE.