How to create a Bitcoin wallet with an open source JavaScript library

4 min reading
Developers / 30 October 2015
How to create a Bitcoin wallet with an open source JavaScript library
How to create a Bitcoin wallet with an open source JavaScript library

BBVA API Market

The world related to cryptocurrencies is always expanding. It has become a fruitful development environment for all kinds of applications. Mobile wallets, connectors with the Bitcoin network, business geolocators that accept virtual currency, video games with bitcoins etc. This is an interesting field for any developer who wants to undertake something. In short, it has become a perfect breeding ground for doing business.

It's certainly true that between late 2013 and early 2014 the price of Bitcoin shot up and, since then, the price has first declined and then its valuation has stabilized (as can be seen in the graph). In any case, it's a field of evident entrepreneurship

Today there is a platform that combines the best of bitcoins and JavaScript, which facilitates the development of applications for this virtual currency. Bitcore is an open source library that works under the Bitcoin protocol. Being an open source solution is a concept advantage: it facilitates the creation of a community that constantly enriches the tool, both independent developers and Bitcoin businesses themselves.

The creator of Bitcore is Bitpay, which in the document launching the tool stated that its objective is that "developers contemplating new Bitcoin projects should not have to resort to using proprietary APIs hosted on services running closed software." The Bitcore platform is ready to work with Node.js on the server side, in a web browser on the client side  and with the ability to interact with Bitcoin nodes.

How to install and start developing with Bitcore

Before you start you need to meet a set of minimum requirements without which it would be impossible for a Bitcore node to connect through Bitcoin. The computer needs 100GB of disk space and 4GB of RAM for storing data on bitcoin blockchains (this is a public accounting system shared between all nodes in the Bitcoin network). In addition, a 64-bit GNU/Linux or Mac OS X (Apple) is required. These would be the steps to begin:

– Install Node.js. Bitpay recommends installing Node Version Manager, that allows for updating versions of Node.js easily. The latest version of Node Version Manager is v.0.29.0. Link for installation.

– Install Bitcore and create a node. It has a command line to create and manage a full Bitcoin node.

– Installation command: npm install -g bitcore. This command not only installs Bitcore, it also synchronizes with blockchain and executes Insight Block Explorer, an open source Bitcoin blockchain explorer with REST and WebSocket APIs that enables developers and Bitcoin businesses to write in virtual wallet code and other applications that need to function and make blockchain queries.

– Command for creating additional nodes: a programmer can create new nodes that are not found within the global NPM installation directory (the one used in the previous step) or run the Bitcore Wallet Service.

– In that case, the developer must do the following:

– Command bitcore create mynodo.

– Creating a node in testnet, an alternative block chain is used for testing. Therefore we would have a TestNet cryptocurrency, which it is different from Bitcoin. It is a way to have a virtual currency to test on. Command for a testnet node: bitcore create mynodo –testnet.

– Both steps make it possible to create a "mynodo" directory, to which dependencies and configuration files can be installed to start operating with the additional node.

– Creating an additional node when there is already a Bitcoin directory for use. bitcore create -d <path-to-datadirectory> mynode

How to configure a bitcoins virtual wallet with Bitcore

One of the first objectives that a developer can have with Bitcore is to configure the bitcoins virtual wallet service. This service uses the same backend that Bitpay Bitcoin wallets use, which in some ways is very similar to what a traditional SPV (Simplified Payment Verification) backend would be (secure connection system with Bitcoin nodes).

Steps to follow:

– Installing dependencies: the main dependency that would have to be installed is MongoDB, an open source NoSQL data database system in JavaScript and document-oriented. In this case we always talk about implementing solutions in this programming language. How do you install MongoDB on Linux or Mac OS X? Here is a tutorial.

– Add the virtual wallet service to the newly-created node: this is possible because it already has a node created and synchronized with the Bitcoin blockchain. Command to execute the virtual wallet:

cd <your node>
bitcore install bitcore-wallet-service
bitcore install insight-api

The new Bitcore API

There are a number of services that can be deployed in any node created with Bitcore through the Insight API. As an example, the web service lets you create an application that provides users with direct interaction with the Bitcore node through an http or https port.

A practical example of the implementation of this service:

MyService.prohttps://bitcore.io/api/totype.setupRoutes = function(app, express) {
  // Set up routes
  app.get('/hello', function(req, res) {
    res.send('world');
  });

  // Serve static content
  app.use('/static', express.static(__dirname + '/static'));
};

MyService.prototype.getRoutePrefix = function() {
  return 'my-service'
};

There are also other additional services that are available in API documentation itself. You can see the presentation of the new Bitcore application programming interface at a developer seminar in the below video. 

If you're a JavaScript developer and want to configure a bitcoin wallet, the services offered by Bitcore can be an effective solution. Check them out.

Furthermore, if you're interested in open source topics, here is a free ebook to download.

Follow us on @BBVAAPIMarket

It may interest you