Client

The @liskhq/lisk-client package provides a default set of packages for use by clients of the Lisk network.

The Client package is a collection of the following packages:

Installation

To add Lisk client as a dependency of your project execute the following command:

$ npm install @liskhq/lisk-client

Upgrade

To perform an upgrade, execute the following command:

npm update @liskhq/lisk-client

Usage

Import using ES6 modules syntax:

import lisk from '@liskhq/lisk-client';

Or using Node.js modules:

const lisk = require('@liskhq/lisk-client');

Or import specific namespaced functionality:

import { APIClient, transactions } from '@liskhq/lisk-client';
// or
const { APIClient, transactions } = require('@liskhq/lisk-client');

Creating an APIClient

const { apiClient } = require('@liskhq/client');

let clientCache;

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

const client = await getClient();

export const useClient = async () => {
    const client = await getClient();
    const blockAtHeight123 = await client.block.getByHeight(123);
    client.subscribe('pluginAlias:eventAlias', ({ data }) => {
      console.log(data.info);
    });
};