Skip to main content

Connect to Event Channels

Describes how to connect to pub/sub architecture which feeds information about your wallet directly into your application.

What are Event Channels?

Event Channels are streams of data which are relevant to a particular topic. At the moment, each organization has a single event channel. This channel streams information related to the state of requests you have made to the API. Event channels allow applications to react in real-time to information as it develops without having to design resource-intensive or highly complex polling patterns. Event channels act similarly to push notifications, except they are designed to be consumed by software applications. If would like to learn more about the pubsub pattern, check out this article by google.

Request Results Channel

When your application makes a request to the API, then the API will respond notifying you whether your request was received. Most requests submitted to the application are long-running. This means that the consequences will not be immediately known. A successful response from the API is not an indication that your action completed successfuly, it merely indicates that we received your request to perform the action.

In order to learn whether your action completed successfully, your application must subscribe to the request result data stream for your organization. This stream will contain JSON formatted messages describing how blockery is handling your request. It will also describe the ultimate results of the request (success/failure).

This channel is the most commonly used event channel. It is implemented by nearly all blockery clients.

How to Connect?

Create an application

You should create an application to process messages fed to you through the event channel. This application will essentially be an always-on daemon which is constantly listening for messages.

Install the SDK

Download or install the pubnub sdk for your preferred programming language.

For most programming languages this will be done via a package manager.

Initialize the Pubnub SDK

Initializing the SDK requires a number of different keys. These can all be obtained from the organization page at https://app.blockery.io/organizations.

You will need the following Keys:

  • Pubnub Authentication Token - This is the token you generate. This token is secret, do not check it into code.
  • Pubnub Channel - This is the name of the event channel you wish to connect to. Follows the pattern <org_id>_request_results
  • Pubnub UUID - This value represents an identifier for your application.
  • Pubnub Subscribe Key - This value tells Pubnub that you are a Blockery customer and that they should consider the rest of the above information in the above context.

Process Messages

Messages will be delivered to a callback function which you define. You can perform any logic you like in this function. Save data to databases, call other apis, trigger business logic, it's up to you.

Example

We have created Javascript and Python examples of connecting to blockery data streams. They are publicly available on our github:

https://github.com/Blockery-io/public_code/tree/main/pubsub

If you like, you can use those examples as a base upon which to build your own applications which handle event channel messages.