RPC wrapper for Nano digital currency nodes written in Ruby
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
spec Adds accounts.to_a, update gems (#12) Oct 1, 2018
.rspec Initial commit, empty gem Jan 18, 2018


Gem Version Gem Downloads Build Status codecov Maintainability

Ruby Nano RPC Logo

Nano RPC is a Ruby wrapper for making Remote Procedure Calls against Nano digital currency nodes. Arbitrary RPC access is provided along with proxy objects that expose helper methods (Wiki).

To run a Nano node locally, see Nano Docker Docs.

Gem version Nanocurrency version
0.22 >= 16.0
0.20 >= 15.0
0.19 >= 14.2, < 15.0


Add this line to your application's Gemfile:

gem 'nano_rpc'

And then execute:

$ bundle

Or install it yourself as:

$ gem install nano_rpc


There are two ways to use this gem. You can use proxy objects that expose helper methods or you make direct RPC calls using Ruby hashes.

Proxy Objects / Helper Methods

Proxy objects are provided to ease interaction with the API by providing logically grouped helper methods. Here we do not strictly follow the grouping as expressed in the Nano RPC Docs. Instead, the following objects are provided:

Account, Accounts, and Wallet each require a single parameter to be passed during initialization (address, addresses, and id, respectively). This parameter is persisted for subsequent calls. All RPC methods are provided directly as methods.

account = NanoRpc.node.account('xrb_1234') # Account address required
accounts = NanoRpc.node.accounts(%w[xrb_1234 xrb_456]) # Array of account addresses required
wallet = NanoRpc.node.wallet('3AF91AE') # Wallet id required

You can call standard RPC methods on each object:

# => {"balance"=>100, "pending"=>5}
# => 100

There are also helper methods to bypass repetitive nested calls:

# => 100
# => 5

To convert from Nano to raw and back, use #to_raw and #to_nano, available on all Numeric objects:

# => 4622.800482

# => 4622800482000000000000000000000000

For a comprehensive guide, see the Wiki.

Direct RPC Calls

The NanoRpc::Node object exposes raw Remote Procedure Call methods according to the Nano RPC Docs.

Every method requires an action, which is passed as the first argument to call. Depending on the action, there may be additional required or optional parameters that are passed as an options hash.

First setup the node connection:

# Connect to the default node (localhost:7076)
node = NanoRpc.node

# or connect to a custom node
node = NanoRpc::Node.new(host: 'mynanonode', port: 1234)

If you're using Nanode or similar service that requires Authorization key in HTTP header, you can specify it using auth:

node = NanoRpc::Node.new(auth: 'someauthkey')

You can also specify custom headers as a hash and they will be sent with every RPC request:

node = NanoRpc::Node.new(headers: { 'Authorization' => 'someauthkey' })

The default timeout for each request is 20 seconds but you can specify a custom value:

node = NanoRpc::Node.new(timeout: 10)

Once the node is setup, use the call method, passing in action and params:

node.call(:account_balance, account: 'xrb_1234')
# => {"balance"=>100, "pending"=>0}

Response data are provided as Hashie objects with integer coercion, indifferent access, and method access.

# => 100
# => 100
# => 100


Logo created by Andrei Luca (Twitter)


The gem is available as open source under the terms of the MIT License.