How To Build a Bitcoin Currency Converter Using the Blockchain.info APIs

The rise of Bitcoin has resulted in the development of a variety of services that enable individuals and companies to track Bitcoin, create and manage Bitcoin wallets, and perform transactions using the cryptocurrency.

One of the most popular Bitcoin websites, Blockchain.info, has a suite of Bitcoin APIs and in this tutorial, we’ll look at how two of those can be used to build a Bitcoin currency conversion application.

Getting started

To start, you will need a hosting account that supports PHP 5.0 or greater and has the PHP curl module installed. In the root web directory of your hosting account, create two empty PHP files, index.php and converter.php.

The index page

Our index page, index.php, should contain a form that we can use to prompt the user for information about the currency conversion desired. In the empty index.php file, paste the following code:

The code above calls two endpoints associated with Blockchain.info's Market Prices and Exchanges Rates API. The first endpoint allows us perform the actual currency conversion for the currency and amount supplied by the user. The second endpoint provides real-time currency conversion information, such as the current buy and sell prices and 15-minute average price. We can use this to display more information to the user about the state of the market in their chosen currency:

Adding a price chart

Blockchain.info offers a Statistics API that provides data that can be used to create charts. One of the endpoints provides historical data for the price of Bitcoin in U.S. dollars. To make Bitcoin-to-USD conversions more useful, we can add on to our converter.php script so it displays a chart of the BTC price over the past 60 days. To create the chart, we can use the Google Charts JavaScript API.

With our charting code in place, users performing currency conversions in U.S. dollars can now visualize how the price has changed over the past two months:

Ideas for further development

Blockchain.info has a set of Wallet APIs that can be used to create new Bitcoin wallets and send and receive payments using them. By integrating these into our application, we can allow users to make payments to others after performing a currency conversion. Additionally, APIs provided by popular third-party Bitcoin wallet providers and exchanges such as Coinbase could be used to allow our users to purchase Bitcoin once they have used the currency converter.

UPDATE:
It did not work on my local WAMP server, which has CURL and PHP 5.34, but it did work once I uploaded it to a shared hosting environment. So I not sure what is actually needed exactly as my WAMP server which I develop on all the time didnt work.