Have an amazing solution built in RAD Studio? Let us know. Looking for discounts? Visit our Special Offers page!
DelphiRAD Studio

What You Need To Make Charts With Blockchain.com API

1-6

Blockchain.com (formerly Blockchain.info) is a cryptocurrency blockchain explorer service, as well as a cryptocurrency wallet and a cryptocurrency exchange supporting Bitcoin, Bitcoin Cash, and Ethereum. They also provide Bitcoin data charts, statistics, and market information, and a series of APIs (Websockets and REST), for their services.

You can use their API to buy and sell cryptocurrency, consult data, calculate taxes, and view charts and statistics. In this article, we will see how easy it is to connect to their API with Delphi REST Debbuger and generate graphics with the data provided by them using IDE Software.

What does Blockchain.com do?

As a cryptocurrency company, Blockchain.com provides a platform for holding, using, managing crypto assets, and exploring cryptocurrency transactions. It also develops financial services standards and infrastructure for cryptocurrencies. The company’s platform provides market data and analytics. It follows cryptocurrency’s aims of being decentralized and anonymous; some of its cryptocurrency products are managed by the end-user and not accessible by Blockchain.com itself. Its main products are its cryptocurrency wallet, exchange, block explorer, and institutional markets offering.

Here’s how to use the Blockchain.com API in a desktop or mobile app

They provide a series of APIs, that you can check here. We will implement the chart API here. The specific documentation you can see here and all the charts that you can get the data from, you can check here.

According to their API, we can have:

  • Full url (with all optional parameters): https://api.blockchain.info/charts/$chartName?timespan=$timespan&rollingAverage=$rollingAverage&start=$start&format=$format&sampled=$sampled
  • Method: GET
  • Parameters:
    • $chartName – Name of the chart you want the data.
    • $timespan – Duration of the chart, default is 1 year for most charts, 1 week for mempool charts. (Optional)
    • $rollingAverage – Duration over which the data should be averaged. (Optional)
    • $start – Datetime at which to start the chart. (Optional)
    • $format – Either JSON or CSV, defaults to JSON. (Optional)
    • $sampled – Boolean set to ‘true’ or ‘false’ (default ‘true’). If true, limits the number of datapoints returned to ~1.5k for performance reasons. (Optional)

How do we call the Blockchain.com API in our program?

In your Delphi IDE, open the REST Debugger tool. The default method already is the one we need so, now we just need to insert the URL. To make things simple, add the URL without the parameters and click on ‘Send Request’:

What You Need To Make Charts With Blockchain.com API - the REST Debugger

We got a 200 status code, so everything is fine. If you click in the ‘Tabular Data’ you can see that the result we want is not well-formatted:

What You Need To Make Charts With Blockchain.com API results from Blockchain.com API

On the JSON Root Element, insert the word ‘values’. This is our JSON Root and now, it will format the result correctly:

What You Need To Make Charts With Blockchain.com API JSON values

Still, on the REST Debugger, copy the components and place them on your form. Now we have the data. We just need to send it to a chart!

How to create a Blockchain.com chart

Delphi comes with a component called TChart. Find it and place it on your form:

What You Need To Make Charts With Blockchain.com API - a chart

Right-click on it, go to Edit Chart -> Add -> Select the ‘Line Chart’ -> uncheck the ‘3D’ option and select OK then CLOSE. Now, we just need to populate it! For that, add a button and on its click event add these lines of code:

What You Need To Make Charts With Blockchain.com API using Firedac
What You Need To Make Charts With Blockchain.com API - a working graph

That is it!! Now you can make graphics from the blockchain.com API, using Delphi!

You can check the full code here: https://github.com/checkdigits/delphi_blockchain_chart_example


RAD Studio Delphi really lives up to the name Rapid Application Development. Why don’t you download a free trial copy today and try this example for yourself and see what it can do for you?


Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial   Upgrade Today

   Free Delphi Community Edition   Free C++Builder Community Edition

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

IN THE ARTICLES