Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Channel

The Channel provides an interface that allows you to perform actions on karai channels.

The Channel class requires a keyring as a parameter for the constructor, so you'll have to create a keyring first.

You must listen for the ready event before doing anything with the channel.

Example Usage:

import { Channel, KeyRing, Utils } from 'libkarai-js';

const keyring = new KeyRing(":memory:");
const channel = new Channel("zeus.karai.io:4200", keyring, false);

channel.on("ready", async () => {
  console.log("Channel info: ", channel.info());
  console.log("My public key is " + Utils.toHexString(keyring.getPub()));
});

channel.on("error", async (error) => {
  // handle the error
});

Hierarchy

  • EventEmitter
    • Channel

Index

Constructors

Events

Properties

Methods

Constructors

constructor

  • new Channel(host: string, keyRing: KeyRing, secure?: boolean): Channel
  • Parameters

    • host: string

      The url of the host.

    • keyRing: KeyRing

      A KeyRing object to use.

    • Default value secure: boolean = true

    Returns Channel

Events

on

  • on(event: "ready", callback: () => void): this
  • on(event: "error", callback: (error: Error) => void): this
  • This is emitted whenever the channel finishes the handshake process. You must wait for it to do any channel operations.

    Example:

    channel.on('ready', async () => {
        // do something with the channel
        const transactions = await channel.transactions.retrieve();
    });

    Parameters

    • event: "ready"
    • callback: () => void
        • (): void
        • Returns void

    Returns this

  • This is emitted whenever the keyring experiences an error initializing.

    Example:

    
      keyring.on("error", (error: Error) => {
        // do something with the error
      });

    Parameters

    • event: "error"
    • callback: (error: Error) => void
        • (error: Error): void
        • Parameters

          • error: Error

          Returns void

    Returns this

Properties

coordinator

coordinator: ICoordinator

The coordinator object contains the methods for interacting with the coordinator.

transactions

transactions: ITransactions

The transactions object contains the methods for interacting with transactions.

Methods

info

Generated using TypeDoc