Bitbank

An easy-to-use Ruby interface for the Bitcoind JSON-RPC API. Work in progress :).

Getting Started

First, you need to be running bitcoind. Download and install the official client from bitcoin.org/

Next, in order for the client to respond to JSON-RPC commands, you need to enable it in the config file. An example of this and a good explanation of the various options can be found at en.bitcoin.it/wiki/Running_Bitcoin

Make sure to set the server, rpcuser, and rpcpassword options.

Connecting

Configure the username and password to match the ones in your bitcoind config. I recommend storing these in a yaml file (see the example config.yml). Once you’ve done that, you can initialize the client and make requests:

client = Bitbank.new('/path/to/bitbank/config.yml')

Accounts and Account Balances

You can have a number of different Bitcoin accounts and addresses.

account = client.new_account('named-account')

account = client.account('named-account') # or account_by_address
puts "#{account.name} has bitcoin address #{account.address}"

client.accounts.each do |account|
  puts "#{account.name}: #{account.balance}"
end

Or you can get the current balance for all your accounts:

client.balance
# => 10.05

Transactions

Each account also has a list of transactions (both sent and received).

account.transactions.each do |transaction|
  puts "[#{transaction.category}] #{transaction.address} #{transaction.amount}"
end

You can move money between your accounts:

account.move('another-account', 0.5)

And of course you can send payments using the library too:

account.pay('1DSwyVqyhKKQwrdFw3jpAEqnrXEjTcTKMB', 1.0)

This would send 1 BTC to me. Which would be really awesome, if you’d like to support the continued development of the gem :).

Contributing to Bitbank

Copyright © 2011 Nick Plante. See LICENSE.txt for further details.