Since working on Min.io, a Bitcoin project with my brothers, I’ve started doing a lot more Bitcoin development. I’m doing contract work for Safe Paper Wallet as well, building and improving their paper wallet generator, which has been incredibly fun to work on. Besides those projects, I’ve created two new open-source projects: Bitcoin Node API and Bitconvert.js.

Bitcoin Node API

While coding the payment server for Min.io, I would communicate with the Bitcoin wallet using JSON-RPC commands. There’s a module that easily interfaces with it, but it’s only for the back-end. Most often I would test payments and need to quickly debug something using a JSON-RPC command. I often had to stop the server, put in the command and run again. This was not ideal. I wanted to reach the commands quickly and effortlessly.

I then created an Express middleware plugin that maps JSON-RPC commands to any chosen url. So for example if you map the middleware to /bitcoin/api and then run http://localhost:5000/bitcoin/api/getinfo, it will return the data produced by the ‘getinfo’ command.

It makes rapid Bitcoin development really easy. Anyone can now interface with their wallet using query strings by just adding a few lines of code. In fact a whole Bitcoin Node API server is now just these few lines of code!

var bitcoinapi = require('bitcoin-node-api');
var express = require('express');
var app = express();

//Username and password relate to those set in the bitcoin.conf file
var wallet = {
  host: 'localhost',
  port: 8332,
  user: 'username',
  pass: 'password'
};

bitcoinapi.setWalletDetails(wallet);
bitcoinapi.setAccess('default-safe'); //Access control
app.use('/bitcoin/api', bitcoinapi.app); //Bind the middleware to any chosen url
app.listen(3000);

Not all commands are supported yet though. I’ll be adding them as I go along. You also have access control available to secure your api. For example:

bitcoinapi.setAccess('restrict', ['dumpprivkey', 'sendmany']);

Setting that restricts access to the ‘dumpprivkey’ and ‘sendmany’ commands.

Check out the Github Repo if you want to contribute.

Bitconvert.js

Bitconvert.js is a simple javascript script that converts any number within a user specified CSS class to and from Bitcoin <-> USD. It’s written with no dependencies and gets the latest prices from MtGox. I wrote this so that any website owner can add a toggle for their prices into Bitcoin if they wanted to sell their goods using Bitcoin. It’s also really simple:

<script src="bitconvert.js"></script>
<span class="amount">$ 5.24</span>
<span class="amount">$ 1</span>
<button onclick="bitconvert.toggleConversion()">Toggle</button>

I’ve been enjoying Bitcoin immensely. It’s great to work on something so incredibly exciting.