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.
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:-
Composer is a Dependency Manager for PHP, and is required for this example.
I created a folder on my server:-
…and downloaded and extracted the zip here from this Git project.
I then navigated in the file manager to:-
…and hit F4 (this opens a terminal at this location). Then I used the command:-
On a remote computer it should now be possible to access one of the example files using the appropriate url, e.g.
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:-
You will find many other APIs on the net of varying complexity including this one, which I understand is quite popular:-
For more detail: Hanging on the BlockChain