Communication Architecture

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 like 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.

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 is a Lisk Elements NPM package that can be imported in any JS client application.

It allows to send 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 application and its' modules & plugins.

Websocket API client example
const { createIPCClient, createWSClient } = require('@liskhq/lisk-api-client');
let clientCache;

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

export const useClient = async () => {
    const client = await getClient();
    const blockAtHeight123 = await client.block.getByHeight(123);
    client.subscribe('pluginAlias:eventAlias', ({ data }) => {
      console.log(data.info);
    });
};
More information about the API Client can be found at the RPC endpoints page.

How to invoke actions

Actions are invoked based on their alias. If input is required, it is provided as second argument.

const { data } = await client.invoke('app:getSchema'); (1)
const { data } = await client.invoke('pluginAlias:getKnownTimestamps'); (2)
const { data } = await client.invoke('moduleAlias:anotherAction'); (3)
const { data }= await client.invoke('app:actionName', input); (4)
1 How to invoke a default application action.
2 How to invoke a plugin action.
3 How to invoke a module action.
4 How to invoke an action that needs some input.

How to publish and subscribe to events

Events are subscribed and published by their alias.

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