What is Klayr Elements?
Klayr Elements is a collection of JavaScript libraries, each tackling a certain topic of blockchain and Klayr-related functionalities.
Package list
Used in frontend
Name | NPM | Specification |
---|---|---|
Client |
The
|
Setup
Dependencies
The following dependencies need to be installed to run the Klayr SDK:
Dependencies | Version |
---|---|
Node.js |
v18 (latest LTS) |
Pre-installation
Klayr Elements requires Node.js as the underlying engine for code execution. The following section describes how to install dependencies such as Node.js and NPM.
Install node
Follow the instructions for your operating system on the Node.js downloads page.
NPM is automatically installed along with Node.js. |
Installation
This section details how to install Klayr Elements for a given distribution.
As all packages in Klayr Elements are independent to each other, they can be installed separately. |
Installation via NPM
To install the latest version of Klayr Elements for use as a dependency in a Node.js project, please proceed with the following:
Complete library
npm install klayr-sdk
npm install @klayr/elements
npm install @klayr/client
npm install @klayr/<package-name>
<package-name>
can be any of the packages in Klayr Elements.
Upon successful completion, NPM will add the Klayr Elements package to your package.json
file.
Load via CDN (Content Delivery Network)
Include the script below using the following HTML.
The klayr
variable will be exposed.
<script src="https://js.klayr.xyz/klayr-client-6.0.0.js"></script>
<script src="https://js.klayr.xyz/klayr-client-6.0.0.min.js"></script>
To include other packages of Klayr Elements, replace @klayr/client
with any of the packages of Klayr Elements.
Usage
Node.js
Simply import, (or require) the package and access its functionality according to the relevant namespace.
Example with the client package:
import klayr from '@klayr/client';
//or
const klayr = require('@klayr/client');
Browser
Load the Klayr Elements script via the CDN.
For example, to load the minified version 6.0.0 of Klayr Elements, include the following script which will then expose the klayr
variable:
<script src="https://js.klayr.xyz/klayr-client-6.0.0.min.js"></script>
<script>
const api = klayr.apiClient.createWSClient('ws://localhost:7887/rpc-ws');
</script>