Hanging on the BlockChain

There has been much discussion (and some excitement) in our house recently about the BlockChain.

Interest is also growing in large financial institutions, and companies are beginning to invest in research & development to ensure that they don't get left behind.

So will the BlockChain change our lives, or is it a techno dead-end?

I'm not sure, but its time I took a closer look.

BlockChain, is that like Bitcoin?

The BlockChain is a decentralised, distributed, virtual ledger. This means that it is not held on a single server, or controlled by an organisation (like a bank or government) and it maintains all transactions in a sequential database.
In principle the BlockChain could be widely used for securely storing information for a range of applications, but its main application at the present time is for storing transactions for cryptocurrencies such as Bitcoin.

Hanging on the BlockChain

Find an API and get hacking

Back in 2013 I wrote a Bitcoin post where I tried to use an API to extract Bitcoin information and data. The api was badly documented, so it took a lot of experimentation to work out roughly how it was supposed to work.

But things have moved on in two & a half years and there are now many well documented APIs such as the one I chose to explore: https://blockchain.info/api

So I used my Raspberry Pi web server to conduct a few tests. This server already has PHP and Lighttpd installed, so it should have just been a case of cloning the api code from Git and trying a few of the examples in this project.

I started by installing composer from a terminal:-

curl -s https://getcomposer.org/installer | php

…and added this text to my /home/pi/.bashrc file:-

alias composer=”/home/pi/php_composer/composer.phar”

Composer is a Dependency Manager for PHP, and is required for this example.

I created a folder on my server:-

/var/www/BC_api

…and downloaded and extracted the zip here from this Git project.

I then navigated in the file manager to:-

/var/www/BC_api

…and hit F4 (this opens a terminal at this location). Then I used the command:-

composer install

On a remote computer it should now be possible to access one of the example files using the appropriate url, e.g.

http://192.168.0.22:9080/BC_api/example/rates.php

I seemed to have a problem initially with Curl. However, after a bit of fiddling around and a couple of re-boots it all came good.

Just about the most simple PHP software I could come up with is this, which only has 4 lines of code and illustrates how straightforward it is using this api:-

…which calculates the current conversion rate and produces this one line output in a web browser:-

However, this API will allow you do much more, including receiving and sending money using you Bitcoin wallet. It also has APIs for other languages including Java, Python, C# and Ruby.

You will find many other APIs on the net of varying complexity including this one, which I understand is quite popular:-
https://github.com/blockcypher/php-client

 

For more detail: Hanging on the BlockChain


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top