DEV Community


Posted on

Building a Bitcoin Calculator with Javascript


Hey guys, I am going to show you how to use Bitcoin exchange rates and currency conversion that supports all major currencies. I am currently using Coindesk which provides API to make data programmatically available to others.

To use the API, you don't need to register, it is free!

You can check out the supported currencies available on their website ( To use the endpoint, you make a request to:[code].json

The code parameter accepts a valid ISO 4217 currency code

A sample request


Take a look at the result, you would notice the rate and the rate_float object, which contains the exchange rate for the local currency to BTC. Below is a formula to convert BTC to your local currency.

Formula = BTC Amount * Exchange Rate = Local currency Price

Building the Bitcoin Calculator

Using a client to consume the JSON data returned from the endpoint is the first thing to do. You can use Asp.Net HttpClient class, Jquery getJson() function which we are going to use here or you can use others you already know.

$.getJSON( "", function( data) {
   var amountInBtc = 0.005; //convert 0.005 btc to usd
   var exchangeRate = parseInt(data.bpi.USD.rate_float);
   var amount = amountInBtc * exchangeRate;
Enter fullscreen mode Exit fullscreen mode

Follow Me:


Top comments (4)

nrobinson2000 profile image
Nathan Robinson

I've been maintaining a project for awhile that allows users to create bitcoin donation pages using JQuery. It features a QR code generator, multiple fiat currencies, and a clickable link generator. Best of all, parameters can be overridden via URL queries.

You can see it in action here:

cryptokit profile image

nice, like the bitcoin calc, very useful.

levelcoding profile image

you have someting what called currency valute?