Client
Table of Contents
The @liskhq/lisk-client package provides a default set of packages for use by clients of the Lisk network.
The |
Installation
To add Lisk client as a dependency of your project execute the following command:
$ npm install @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/lisk-client');
let clientCache;
export const getClient = async () => {
if (!clientCache) {
clientCache = await apiClient.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);
});
};