Options
All
  • Public
  • Public/Protected
  • All
Menu

Class WebSocketClient

An object repesenting a connection to a Terra node's WebSocket RPC endpoint. This allows for subscribing to Tendermint events through WebSocket.

Events

error emitted when error raises connect emitted after connection establishment reconnect emitted upon every attempt of reconnection destroyed emitted when socket has been destroyed

Example

import { WebSocketClient } from '@terra-money/terra.js';

const wsclient = new WebSocketClient("ws://localhost:26657/websocket");

wsclient.subscribe('NewBlock', {}, (data) => {
console.log(data.value);

// close after receiving one block.
wsclient.destroy();
})

wsclient.subscribe(
'Tx',
{
'message.action': 'send',
'message.sender': ['CONTAINS', 'terra1...'],
},
(data) => {
console.log(data.value);

// close after receiving one send Tx
wsclient.destroy();
});

Hierarchy

  • EventEmitter
    • WebSocketClient

Index

Constructors

constructor

  • new WebSocketClient(URL: string, reconnectCount?: number, reconnectInterval?: number): WebSocketClient
  • WebSocketClient constructor

    Parameters

    • URL: string

      The WebSocket endpoint URL on the Tendermint RPC server. Ex: ws://localhost:26657/websocket

    • reconnectCount: number = 0

      0 for not to attempt reconnect, -1 for infinite, > 0 for number of times to attempt

    • reconnectInterval: number = 1000

      retry interval in milliseconds

    Returns WebSocketClient

Properties

isConnected

isConnected: boolean

Methods

destroy

  • destroy(): void

start

  • start(): void

subscribe

subscribeTx