Communication Architecture

The open Lisk communication architecture is based on IPC Unix Sockets and WebSocket. The Application exposes an IPC socket that can be used by internal components such as modules and plugins, and by any external service like other scripts in JS, a tool in Rust, or a Python daemon. These external services can connect to this socket and listen to events in the network, or invoke various actions of the Application.

communication architecture

Action and event interfaces

The Lisk Framework defines actions and events which can be invoked and subscribed through a channel.

All modules and plugins will be given a channel to communicate with the application via actions and events.

The API client

The API client can be imported in any JS client application.

It allows sending API requests to a node via IPC or WS.

It also provides an interface to subscribe to all events and to invoke actions of the blockchain application and its' modules & plugins.

The apiClient can also be imported from the @liskhq/lisk-client package.
Websocket API client example
const { createIPCClient, createWSClient } = require('@liskhq/lisk-api-client');
let clientCache;

const getClient = async () => {
  if (!clientCache) {
    clientCache = await createWSClient('ws://localhost:8080/ws');
  }
  return clientCache;
};

const useClient = async () => {
  const client = await getClient();
  const blockAtHeight123 = await client.block.getByHeight(123);
  client.subscribe('app:block:new', ( data ) => {
    console.log("new block:",data);
  });
  return blockAtHeight123;
};

useClient().then((val) => {
  console.log("val:",val);
});
More information about the API Client can be found at the RPC endpoints page.

Aliases

Events and actions are identified by their alias.

Example alias: monitor:getTransactionStats

The alias always consists of the following parts:

  1. Prefix: Consists of the module or plugin name that provides the respective action or event. Equals app if it’s an application event or action.

  2. Separator: Prefix and suffix are always separated by a colon :.

  3. Suffix: The respective name of the event or action.

How to publish and subscribe to events

Events are published inside lifecycle hooks of the module. The channel is available inside the lifecycle hooks, which allows to subscribe and publish to events, as well as invoking actions in the network.

Publishing an event
channel.publish('pluginAlias:timestamp', { info: 'sample' });

Subscribe to an event by utilizing The API client.

Subscribing to an event
client.subscribe('pluginAlias:timestamp', ( data ) => {
  console.log(data);
});
More information about available events and actions can be found at the RPC endpoints page.

How to invoke actions

The first argument is always the alias. If input data is required, it is provided as second argument.

Examples: How to invoke different kind of actions with the API client
const data = await client.invoke('app:getSchema'); (1)
const data = await client.invoke('app:actionName', input); (2)
client.invoke('monitor:getTransactionStats').then((val) => { (3)
    console.log(val);
});
1 How to invoke an action.
2 How to invoke an action that needs some input data.
3 Example of how to invoke an action of the monitor plugin.