Spectrum API Documentation

Available Spectrum endpoints

Code samples of Spectrum clients

# get_actions endopoint

Here is the sample subscription message for get_actions endpoint:

{
  "apikey":"test-api-key",
  "event":"subscribe",
  "type":"get_actions",
  "data":  {
              "account":"eostribeprod",
              “actions":[“transfer”,”buyram”]
   }
}

Fields description for get_actions:

Sample Python client for get_actions:

import json
from websocket import create_connection

path="streaming"
url = "wss://telos.spectrumeos.io/"+path

actionsList = ["transfer","buyram"]
data = {"account":"eostribeprod"}
messageBody = {
   "apikey":"test-api-key",
   "event":"subscribe",
   "type":"get_actions",
    "data": data
 }
ws = create_connection(url)
messageJson = json.dumps(messageBody)
ws.send(messageJson)

while True:
   response = ws.recv()
   print(response)
ws.close()

Sample JS Client code for get_actions:

let socket = new WebSocket("wss://telos.spectrumeos.io/streaming");

var actionsList = ["transfer","buyram"]; 
var messageBody = {
   "apikey":"test-api-key",
   "event":"subscribe",
   "type":"get_actions",
   "data": {"account":"eosio"}
};


socket.onopen = function(e) {
  console.log("[open] Connection established");
  console.log("Sending to server: "+JSON.stringify(messageBody));
  socket.send(JSON.stringify(messageBody));
};

socket.onmessage = function(event) {
  html_log("[message] Data received from server: "+event.data);
};

socket.onclose = function(event) {
  if (event.wasClean) {
    html_log("[close] Connection closed cleanly, code=${event.code} reason=${event.reason}");
  } else {
    html_log("[close] Connection died");
  }
};

socket.onerror = function(error) {
  html_log("[error] ${error.message}");
};

function html_log(data) {
  document.getElementById("log").innerHTML = data;
}

Sample NodeJS Client code for get_actions:

global.fetch = require('node-fetch')
global.WebSocket = require('ws')

const telosTrxStatus =  () =>{
    const messageBody = {
          "apikey": "test-api-key",
          "event": "subscribe",
          "type": "get_actions",
          "data": {
              "account": "eosio", 
              "actions": ["transfer"]
          }
      }
      const  socket = new WebSocket("wss://telos.spectrumeos.io/streaming")
    
      socket.onopen = () => {
          socket.send(JSON.stringify(messageBody));
      }
  
      socket.onmessage = (event) => {
          console.log('Telos websocket:', JSON.parse(event.data))
    }
    socket.onclose = (event)=> {
      console.log("Telos socket connection closed:" +event.data)
    }
    socket.onerror = function(error) {
          console.log("Telos websocket got error: " +error.message)
      }
  
}

telosTrxStatus()

# get_blocks endopoint

Request message format for get_blocks endpoint:

{
  "apikey":"test-api-key",
  "event":"subscribe",
  "type":"get_blocks"
}

Fields description:

Sample Python client for get_blocks:

import json
import pprint
from websocket import create_connection

path="streaming"
url = "wss://telos.spectrumeos.io/"+path

messageBody = {
   "apikey":"test-api-key",
             "event":"subscribe",
              "type":"get_blocks"
             }

ws = create_connection(url)
ws.send(json.dumps(messageBody))

while True:
   pprint.pprint(json.loads(ws.recv()))
ws.close()

Sample JS Client code for get_blocks:

let socket = new WebSocket("wss://telos.spectrumeos.io/streaming");


var messageBody = {
   "apikey":"test-api-key",
   "event":"subscribe",
   "type":"get_blocks"
};

socket.onopen = function(e) {
  html_log("[open] Connection established");
  html_log("[subscribe] sending message to server");
  socket.send(JSON.stringify(messageBody));
};

socket.onmessage = function(event) {
  html_log("[message] Data received from server: "+event.data);
};

socket.onclose = function(event) {
  if (event.wasClean) {
    html_log("[close] Connection closed cleanly, code=${event.code} reason=${event.reason}");
  } else {
    html_log("[close] Connection died");
  }
};

socket.onerror = function(error) {
  html_log("[error] ${error.message}");
};

function html_log(data) {
  document.getElementById("log").innerHTML = data;
}

# get_transaction endopoint

Here is sample subscription message for get_transaction endpoint:

{
  "apikey":"test-api-key",
  "event":"subscribe",
  "type":"get_transaction",
  "data": {"account":"eosio"}
}

Fields description for get_transaction:

Sample client in Python for get_transaction:

import json
import pprint

from websocket import create_connection

path="streaming"
url = "wss://telos.spectrumeos.io/"+path

data = {"account":"eosio"}

messageBody ={
   "apikey":"test-api-key",
             "event":"subscribe",
              "type":"get_transaction",
             "data": data
             }
ws = create_connection(url)
messageJson = json.dumps(messageBody)
ws.send(messageJson)

while True:
   pprint.pprint(json.loads(ws.recv()))
ws.close()

Sample JS Client for get_transaction:

let socket = new WebSocket("wss://telos.spectrumeos.io/streaming");

var messageBody ={
              "apikey":"test-api-key",
              "event":"subscribe",
              "type":"get_transaction",
              "data": {"account":"eosio"}
             };


socket.onopen = function(e) {
  console.log("[open] Connection established");
  console.log("Sending to server: "+JSON.stringify(messageBody));
  socket.send(JSON.stringify(messageBody));
};

socket.onmessage = function(event) {
  html_log("[message] Data received from server: "+event.data);
};

socket.onclose = function(event) {
  if (event.wasClean) {
    html_log("[close] Connection closed cleanly, code=${event.code} reason=${event.reason}");
  } else {
    html_log("[close] Connection died");
  }
};

socket.onerror = function(error) {
  html_log("[error] ${error.message}");
};

function html_log(data) {
  document.getElementById("log").innerHTML = data;
}

# get_table_rows endopoint

Below is the sample subscription message for the newly added get_table_rows endpoint:

{
  "apikey":"test-api-key",
  "event":"subscribe",
  "type":"get_table_rows",
  "data": {
    "code":"account name",
    "table":"table name",
    "scope":"scope name"
   }
}

Fields description for get_table_rows:

Sample client in Python for get_table_rows:

import json
import pprint

from websocket import create_connection

path="streaming"
url = "wss://telos.spectrumeos.io/"+path

messageBody ={
   "apikey":"test-api-key",
             "event":"subscribe",
             "type":"get_table_rows",
             "data": data
             }
ws = create_connection(url)
messageJson = json.dumps(messageBody)
ws.send(messageJson)

while True:
   pprint.pprint(json.loads(ws.recv()))
ws.close()

Single JS library for all endpoints and chains:

var chain = "telos"; # eos | worbli | lynx | worbli | ...
var apikey = "test-api-key"; # real API key will be required for EOS chain

var onOpenHandler = function(e) { 
	console.log("[open] Connection established"); 
};

var onMessageHandler = function(event) {
	console.log(event.data);
};

var onCloseHandler = function(event) {
	console.log("[close] Connection closed");
};

var onErrorHandler = function(error) {
	console.log("[error] ${error.message}");
};

var socket = open_connection(chain, apikey, onOpenHandler, onMessageHandler, onCloseHandler, onErrorHandler);

get_blocks(socket);

get_actions(socket, "eosio", ["transfer","buyram"]);

get_transaction(socket, "eosio");

get_table_rows(socket, "eosio", "table", "scope");

Additional documentation:

Homepage with demo of running JS client.

GitHub: Spectrum API Java websocket endpoint.

Please see our SteemIt posts for additional information:
https://steemit.com/@eostribe/

Telegram group: Spectrum Tech Group

Support email: [email protected]