Blockchain API Utilization

Blockchain API and Its Utilization

Blockchain allows data providers and consumers to exchange information directly in a single, open system instead of subscribing to dozens of centralized services around the world and programming their software to communicate with each of their APIs. Read this blockchain API tutorial to learn how to use it for your specific needs.

An API (application programming interface) is a description of methods (a set of classes, procedures, functions, structures, or constants) that a single computer program can use to interact with another program. It is usually included in the description of any Internet protocol (for example, RFC), software framework, or standard call to the functions of the operating system. It is often implemented by a separate software library or operating-system service. Developers usually use blockchain API to write all sorts of applications.

An API defines the functionality provided by a program (module, library) and allows abstraction from exactly how this functionality is implemented. Software components interact with each other through APIs. In this case, the components usually form a hierarchy: high-level components use an API of low-level components, and these, in turn, use an API of even lower-level components. Protocols for data transmission over the Internet are built according to this principle.

The standard protocol stack (OSI network model) contains 7 layers (from the physical bit-transfer layer to the application protocol layer, similar to the HTTP and IMAP protocols). Each level uses the functionality of the previous (“underlying”) level of data transfer, and, provides the necessary functionality to the next (“overlying”) level.

Note:the concept of a protocol is close in meaning to the concept of an API. Both are abstractions of functionality, except that protocols involve data transfer, while APIs are related to the interaction of applications.

Blockchain API Variety

The development of blockchain software usually includes various difficult parts. One of the most important is creating blockchain API interfaces. There are projects that help users and developers by providing the following API services:

an incredibly easy way for websites to receive payments in Bitcoin. Such a service is completely secure and is ideal for business or personal use

web sockets: a streaming socket with low latency, providing data on new blocks and transactions.

Let’s start with the blockchain wallet API review. The blockchain Wallet API provides a simple interface. To use this API, you will need to start a small local service that is responsible for managing your wallet. Your application interacts with this service locally via HTTP API calls.

Now you can transfer Bitcoin from your new blockchain wallet API. All transactions are worth a 0.0001 BTC miner’s fee. This is how it looks in PHP:

WebSocket API allows developers to obtain real-time data on new transactions and blocks.

Start with the URL link wss://ws.blockchain.info/inv. When the socket is deployed, the user subscribes to the channel by sending an “op” message {“op”:”ping”}. Then, subscribe to notifications about all new Bitcoin transactions {“op”:”unconfirmed_sub”}. And finally, subscribe to an address {“op”:”addr_sub”, “addr”:”$bitcoin_address”}.

As for blockchain data API, some data API calls are available with CORS headers if you add a &cors=true parameter to the GET request.

CORS (cross-origin resource sharing) is a technology of modern browsers that provides a web page with access to resources of another domain. Until recently, the main way to overcome the limitations imposed by the same-origin-policy regarding XSS requests was to use JSONP. JSONP itself has a fatal limitation: it can only receive data by the GET method. Sending data through the POST method remains inaccessible.

The technology itself is quite simple. There are three domains that wish to download resources from the server. In order to make this possible, the web server, which delivers content, is sufficient to indicate a list of trusted domains in the response header Access-Control-Allow-Origin: A, B, C. Then the limitations of the same source principle on the requested pages will not apply for the pages of these domains. To initiate a cross-origin request, the client browser adds an origin request to the HTTP request (the site domain from which the request originates). For example, the page http://www.a.com/page.html tries to get data from the page http://www.b.com/cors.txt.

The Charts API method can be utilized to receive information about blockchain.info’s chart:

1

2

3

4

5

6

7

8

9

10

11

"status":"ok",

"name":"Confirmed Transactions Per Day",

"unit":"Transactions",

"period":"day",

"description":"The number of daily confirmed Bitcoin transactions.",

"values":[

{

"x":1442534400,// Unix timestamp (2015-09-18T00:00:00+00:00)

"y":188330.0

},

...

Stats API can be utilized to receive information about blockchain.info’s statistics:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

"market_price_usd":610.036975,

"hash_rate":1.8410989266292908E9,

"total_fees_btc":6073543165,

"n_btc_mined":205000000000,

"n_tx":233805,

"n_blocks_mined":164,

"minutes_between_blocks":8.2577,

"totalbc":1587622500000000,

"n_blocks_total":430098,

"estimated_transaction_volume_usd":1.2342976868108143E8,

"blocks_size":117490685,

"miners_revenue_usd":1287626.6577490852,

"nextretarget":431423,

"difficulty":225832872179,

"estimated_btc_sent":20233161880242,

"miners_revenue_btc":2110,

"total_btc_sent":184646388663542,

"trade_volume_btc":21597.09997288,

"trade_volume_usd":1.3175029536228297E7,

"timestamp":1474035340000

Bitcoin API

Accepting payments in Bitcoin is becoming more popular and in demand. There are different methods for accepting payments in Bitcoin on a website. One of the most convenient methods is blockchain API. Here, you do not need to be tied to a specific language or SDK; you do not even need to register there. All that is needed is to have a wallet for accepting Bitcoin and time to connect fairly simple APIs to your system. In addition, the client will see not your wallet, but a temporary wallet of the exchange.

Before speaking directly about the code (we will use PHP in the examples, but that can easily be implemented in Java, Python, etc.), it is necessary to clarify the payment acceptance mechanism itself.

Blockchain returns its temporary wallet to receive payments to the user.

The user shows this wallet to the client, as well as a small set of instructions on what to do about it.

The client pays (transfers funds to the wallet).

The user should wait for the validation of the payment in the Bitcoin system.

In case of successful validation by the blockchain system, a script will be called upon the user’s site (the user must indicate which one), and all transaction data is transferred.

After that, the fact of payment is safely confirmed within the user system.

To get a temporary wallet, you should send a series of data:

The URL of the script that will be pinged in case of successful confirmation of the transaction. It should be noted that it is recommended to specify a certain parameter (or even a few), in order to identify the payment in the current system. One can simply specify the client’s ID in the user system and enter any data into the database, but only after receiving confirmation of the transaction. However, the official documentation recommends using a pre-created payment number and any verification phrase. In total, we get a URL with the parameters as in the usual GET transfer request. For the Blockchain system, this parameter is called a callback. The value should be encoded as a URL link.

User wallet for receiving payment. Blockchain will transfer the received money to this wallet. The parameter is called an address.

The last parameter is called a method, and is used to create a temporary wallet.

This data is sent to the Blockchain script (https://blockchain.info/api/receive), with each of the parameters being the usual GET parameter. The result of its execution is processed by the user system (the result will be in JSON format). All about blockchain info API is stated in the blockchain API documentation.

Now the user is ready to accept payment to his/her wallet, but is not able to register the fact of its receipt from the system. The user should remember that in a real system, it is advised to use a well-thought-out and well-written code, as well as a database to store prepared payments (it is important to store the payment number, the user ID in the system and the verification phrase or its components). In addition, the time to validate a payment can be different and very significant, and the Bitcoin rate can change. The user has two options: to keep the rate at the time of making the payment, or request it upon the receipt of confirmation of the transaction.

The transaction confirmation receipt file should be called receive_payment.php and should be stored at the root of the site; when requesting a temporary wallet, the user specified its name when creating the $callback_url.

In fact, the script for the same payment will be invoked not just once, but according to the number of its confirmations on individual nodes. This means that the user must check if there has been a confirmation before.

Blockchain gives many parameters:

transaction_hash – unique transaction hash

input_transaction_hash – unique hash of the original transaction

input_address – Blockchain wallet, which will receive payment

destination_address – the user’s wallet to which the payment will be sent

confirmations – the number of confirmations by nodes (it is recommended to accept payment confirmation in case this parameter has a value greater than or equal to 6).

The parameter called value generates values in Satoshi, not Bitcoin (1 Satoshi = 0.00000001 BTC). Therefore, the resulting value should be reduced to Bitcoin. The parameters called invoice_id and secret are set by the user at the stage of receiving a blockchain wallet. Accordingly, there may be more or less of them, and they can have any names.

It is recommended to store the received value in Bitcoin in the payment history; however, one should convert it to another currency (dollars, for example), which is used by the user system. If the system works only with Bitcoin, then nothing needs to be converted.

There is separate exchange-rate API documentation for converting Bitcoin to other currencies. The user must specify two parameters:

the name of the currency (the list of currencies is available in the documentation, and the user can also get it using the calling print_r ($exchange_data_obj);)

the number of bitcoins the user wants to exchange

Blockchain Development Platforms and APIs

Today, there are a number of companies that develop platforms and projects that offer application development tools. Blockchain.info has a number of blockchain info API for working with their e-wallet service (this is one of the largest e-wallet services), designed to send and receive payments and perform other operations. The chain has created interfaces for accessing data contained in full nodes of the distributed registry of records, and standard information requests: for example, about your Bitcoin balance. In addition, you can send notifications when an action is performed at a particular address.

Stellar is a semi-decentralized (served by gateway organizations, not miners), publicly accessible logbook and unified development environment (blockchain API, multi-signature API) tied to the Stripe payment network. There are other companies that have blockchain wallet API with a multilateral signature, such as Block.io, Gem, BlockCypher, etc.

In the future, a more unified blockchain API development environment will be required, including diverse and evolving components of the blockchain ecosystem (storage, file maintenance, wallet interaction, mobile payments, identity verification, and reputation). Smart contracts will allow us to create a global “meteorological data market” in which consumers will request real-time data and receive data in a universal format (using blockchain info API).

Centralized data providers can say goodbye to their own formats and sales campaigns, and instead deliver data to the globally accessible “meteorology market dAppe.” It is possible to link the development environment of blockchain to other large segments: for example, machine-to-machine (M2M) communication and the infrastructure of the “Internet of things” network for rapid application development. An example of this type of advanced integrated application in the distant future could be smartwatches that interact with traffic sensors within the infrastructure of a smart city in order to automatically reserve and pay for traffic using smart contracts in Bitcoin.

API Operating Systems And Diversity Issues

Almost all operating systems (UNIX, Windows, OS X, etc.) have an API with which programmers can create applications for an operating system. The main API operating system is a set of system calls. It should be noted that the developer often has several different APIs to achieve the same result. In addition, each API is usually implemented using the API program components of a lower level of abstraction. For example: in order to see the line “Hello, world!” In the browser, you just need to create an HTML document with a minimal title and the simplest body containing the given line.

When the browser opens this document, the browser program will transfer the name of the file (or a file descriptor that is already open) to the library that processes HTML documents, which, in turn, will read this file using the operating API system and then call it through API library of standard-graphic/primitive operations of the “clear window” type. Write “Hello, world!” in the selected font. During the execution of these operations, the library of graphics primitives will access the window interface library with the corresponding requests. This library will have already contacted the operating system API to write data to the video card buffer.

At the same time, there are actually several possible alternative APIs at almost every level. For example, we could write the source document not on HTML, but on LaTeX. We could use any browser for display. Different browsers, generally speaking, use different HTML libraries, and all of this can be compiled using different primitive libraries and on different operating systems.

The main difficulties of existing multi-level API systems, therefore, are:

The complexity of porting software code from one API system to another (for example, when changing the OS)

Loss of functionality when moving from a lower level to a higher level. Roughly speaking, each API “layer” is created to facilitate the execution of some standard set of operations. But at the same time, it is really difficult, or it becomes fundamentally impossible to perform other operations that are provided by a lower API level.

Difficulties in porting program code when moving from one API to another. They often appear when transferring modules to other operating systems.

Reducing the scope of interface functionality when moving from lower-level to high-level management. In this case, the implementation of a strictly-defined class of tasks is facilitated. At the same time, access to the controls of other regulators is lost. After all, the lower level allows you to easily manage the basic components of the program.

The classification of software interfaces is closely related to the purpose and capabilities of the applications that are controlled through them. In fact, when operating a complex system, there are often alternative APIs that allow the solving of the same problems by other means.

Separate groups allocate interfaces for managing graphic components of software modules (wxWidgets, Qt, GTK, etc.), operating systems (Amiga ROM Kernel, Cocoa, Linux Kernel API, OS/2 API, POSIX, Windows API), sound (DirectMusic/DirectSound, OpenAL), window interfaces, and so on. Their separation is determined by the level of application in the hierarchy and functionality. Users of computer games usually do not suspect that this graphic API provides them with such quick drawing of pictures and amazing brightness of images.

Global blockchain API often include interfaces of individual programming languages. With their help, you can manage the solution of very specific and local tasks. It all depends on the implementation of the specific algorithm.

Summary

Blockchain raises a huge number of extremely important issues. Its utilization has a wide range of advantages: refusal of third parties, protection of transactions, secure trade, sharing of resources, guaranteed transactions, automatic execution of contracts, etc.

Application programming interfaces (APIs) are now included in the common infrastructure, which is cryptographically protected (blockchain).

Blockchain is used as a new form of database: for example, as a place for permanent storage of immutable cryptographic blockchain API key (or hashe) in distributed hash tables (DHT), which are associated with a large amount of data stored off-chain.

A new type of browser will allow users to run decentralized applications (Dapps), not just web pages (for example, Mist in Ethereum).

It can also solve a number of more difficult issues. One of these is centralization. Blockchain technology could prove very useful in the world of the future, where both centralized and decentralized models will be applied. It will not only destroy existing stereotypes and schemes, but also contribute to the development of large ecosystems that combine old and innovative approaches.

If you need more information about blockchain technology, contact the Applicature team.

Related Posts

One thought on “Blockchain API Utilization”

Blockchain Technologies (blockchaintechnologies.com)
Blockchain Technologies is a huge static content website that covers practically every single question you might have about blockchain. Additionally, the site also has a news section where stories from the largest cryptocurrency news blogs are gathered.
I added this site to this list of the 27 best cryptocurrency blogs for three main reasons. The first is that the content is absolutely amazing. It is very obvious that the writer spent A LOT of time researching about cryptocurrencies. Secondly, the UI of the website is astonishing. The colors are very well picked, the site charges in the blink of an eye and it is completely responsive. And finally, although the Blockchain Technologies blog has a couple Ads, it is very clear that the main objective of the site is to inform, and not to just make money with visitors.