EOS WebSocket Javascript Library
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples
types
.gitignore
CHANGELOG.md
README.md
index.ts
package.json
tsconfig.json
tslint.json

README.md

EOS WebSocket

EOSWS Servers

Mainnet

  • wss://eosws.mainnet.eoscanada.com/v1/stream?token=[API TOKEN]

Kylin

  • wss://eosws.kylin.eoscanada.com/v1/stream?token=[API TOKEN]

Install

npm

$ npm install --save eosws

Quickstart

Get Actions

import WebSocket from "ws";
import { get_actions, parse_actions } from "eosws";

const API_TOKEN = "eyJ...IBg";
const origin = "https://example.com";
const ws = new WebSocket(`wss://<SERVER>/v1/stream?token=${API_TOKEN}`, {origin});

ws.onopen = () => {
    ws.send(get_actions("eosio.token", "transfer"));
};

ws.onmessage = (message) => {
    const actions = parse_actions(message.data);

    if (actions) {
        const { from, to, quantity, memo } = actions.data.trace.act.data;
        console.log(from , to, quantity, memo);
    }
};

Get Table Rows

import { get_table_rows, parse_table_rows } from "eosws";

ws.onopen = () => {
    ws.send(get_table_rows("eosio", "eosio", "voters"));
};

ws.onmessage = (message) => {
    const table = parse_table_rows<Voters>(message.data, voters_req_id);

    if (table) {
        const {owner, producers, last_vote_weight} = table.data.row;
        console.log(owner, producers, last_vote_weight);
    }
};

Related Javascript

Related Video

API

Table of Contents

get_actions

Get Actions

Parameters

  • account string Account
  • action_name string Action Name
  • receiver string? Receiver
  • options (optional, default {})

Examples

ws.send(get_actions("eosio.token", "transfer"));

Returns string Message for ws.send

get_table_rows

Get Table Deltas

Parameters

  • code string Code
  • scope string Scope
  • table_name string Table Name
  • options object Optional parameters (optional, default {})
    • options.req_id string? Request ID
    • options.start_block number? Start at block number
    • options.fetch boolean? Fetch initial request

Examples

ws.send(get_table_rows("eosio", "eosio", "global"));

Returns string Message for ws.send

unlisten

Unlisten to WebSocket based on request id

Parameters

Examples

ws.send(unlisten("req123"));

generateReqId

Generate Req ID

Examples

generateReqId() // => req123

Returns string Request ID

parse_actions

Parse Actions from get_actions from WebSocket onmessage listener

Parameters

  • data WebSocketData WebSocket Data from message event
  • req_id string? Request ID

Examples

const actions = parse_actions<any>(message);

Returns ActionTrace Action Trace

parse_table_rows

Parse Table Deltas from get_table_rows from WebSocket onmessage listener

Parameters

  • data WebSocketData WebSocket Data from message event
  • req_id string? Request ID

Examples

const table_deltas = parse_table_rows<any>(message);

Returns ActionTrace Action Trace

parse_ping

Parse Ping from WebSocket onmessage listener

Parameters

  • data WebSocketData WebSocket Data from message event

Examples

const ping = parse_ping(message);

Returns Ping Ping