EOS WebSocket Javascript Library
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 Add multiple action example Oct 10, 2018
types update table_rows Oct 16, 2018
.gitignore Update changes EOSWS v1.1.0 Oct 9, 2018
CHANGELOG.md Update changes EOSWS v1.1.0 Oct 9, 2018
README.md Update README.md Nov 23, 2018
index.ts Update changes EOSWS v1.1.0 Oct 9, 2018
package.json v1.2.1 Oct 16, 2018
tsconfig.json Support for browser Sep 28, 2018
tslint.json Move to src Sep 20, 2018

README.md

EOS WebSocket

⚠️DEPRECATED ⚠️

Library is now being maintained at https://github.com/dfuse-io/eosws-js

Go to https://www.dfuse.io and click on "Get a Free API Key"

EOSWS Servers

Mainnet

  • wss://mainnet.eos.dfuse.io/v1/stream?token=[API TOKEN]

Kylin

  • wss://kylin.eos.dfuse.io/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