- Toshendra Kumar Sharma
- October 17, 2018
Since Bitcoin first broke into the world wide web, it has made several upgrades to its original code making it easier for the average user to get started with Bitcoin. As you may already know, an API refers to an Application Programming Interface which is designed to simplify interacting with a piece of software. It typically contains a host of subroutine definitions, communication protocols, and tools that can be used to build applications on top of the existing functionality. In this article, we take a look at the various kind of APIs available for blockchains and also learn the methods of invoking these functions in a website.
Benefits of Using Blockchain APIs
Before jumping into blockchain APIs, we must first have a basic understanding of how blockchains work. A typical blockchain consists of the following three basic steps:
(a) A transaction is generated by a bitcoin client and broadcast it to the network where it sits in the memory pool waiting to be processed.
(b) The transaction is picked up by miners and added to a block.
(c) The miners solve the block, and the transaction is finally added to the blockchain.
It is evident from the process above that; it is too complicated for every person who wants to use blockchains to set up their network. That is precisely why Blockchain API’s exist. Blockchain API’s can consequently be used for many applications which wouldn’t be possible with just blockchains. For instance, using the decentralized security offered by blockchains to verify cryptographic key exchanges requires some form of an API. Also since blockchains are somewhat expensive to be used for performing computing tasks, they can instead be used to exchange tokens that can be used to rent computing power. Etheroll is one such example of a decentralized application that relies on the blockchain for ensuring fairness of the betting game. The bulk of the user interface and other features for the website are similar to that of a traditional website. However, the essential component, that is computing the dice roll fairly for all players is done using a transaction on the Ethereum Blockchain. Another application of blockchain APIs for security is for the management of supply chain logistics. VeChain is one of the biggest players in the blockchain based logistics sector, and it uses blockchain APIs to make sure that the product is authentic and trackable in real time.
How To Integrate Blockchain APIs in a Website
There is a wide variety of different blockchain APIs each of which caters to unique needs such as Neuroware, Factom Alpha, Blockchain (for blockchain.com), ChromaWay, Coinbase, Gem, Tierion and many others. For this guide, we shall consider one of the simplest applications of setting up a Blockchain API for accepting Bitcoin payments on a website. The process depends on Receive Payments API V2 of Blockchain to generate new unused addresses to receive payments for a specific extended public key (xPub):
-
Request for an API key users must set up a wallet at www.blockchain.info and request for an API key at
-
Generation an extended public key (xPub): After generating a wallet at the address specified above, the xPub can be found in:
Settings -> Addresses -> Manage -> More Options -> Show xPub
-
Generating a unique address for every customer: The basic URL for creating a new request for every customer is:
https://api.blockchain.info/v2/receive?xpub=$xpub&callback=$callback_url&key=$key
The three main parameters for this request are as follows:
-
xpub – Your xPub.
-
callback_url – The callback URL to be notified when a payment is received.
-
key – Your blockchain.info receive payments v2 API key (created in step 1).
Every call to the server will increment the index by one to avoid showing the same address to different customers.