![1 | Embarcadero RAD Studio Delphi C++Builder Blogs 1 6](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2021/08/1-2176575.png?resize=1140%2C694&ssl=1)
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.
Table of Contents
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’:
![image9281200 | Embarcadero RAD Studio Delphi C++Builder Blogs What You Need To Make Charts With Blockchaincom API the REST Debugger](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2021/08/image-9281200.png?resize=567%2C379&ssl=1)
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:
![image5837368 | Embarcadero RAD Studio Delphi C++Builder Blogs What You Need To Make Charts With Blockchaincom API results from Blockchaincom API](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2021/08/image-5837368.png?resize=567%2C98&ssl=1)
On the JSON Root Element, insert the word ‘values’. This is our JSON Root and now, it will format the result correctly:
![image6880467 | Embarcadero RAD Studio Delphi C++Builder Blogs What You Need To Make Charts With Blockchaincom API JSON values](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2021/08/image-6880467.png?resize=567%2C243&ssl=1)
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:
![image2441863 | Embarcadero RAD Studio Delphi C++Builder Blogs What You Need To Make Charts With Blockchaincom API a chart](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2021/08/image-2441863.png?resize=567%2C358&ssl=1)
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:
![image2342370 | Embarcadero RAD Studio Delphi C++Builder Blogs What You Need To Make Charts With Blockchaincom API using Firedac](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2021/08/image-2342370.png?resize=567%2C228&ssl=1)
![image7101046 | Embarcadero RAD Studio Delphi C++Builder Blogs What You Need To Make Charts With Blockchaincom API a working graph](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2021/08/image-7101046.png?resize=567%2C278&ssl=1)
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?
Design. Code. Compile. Deploy.
Start Free Trial Upgrade Today
Free Delphi Community Edition Free C++Builder Community Edition