Spectrum API - JS Client library with samples

in #spectrum5 years ago (edited)

spectrum.jpeg

EOS Tribe published JS Client library for Telos and Worbli Spectrum API endpoints:

Telos JS libraries:

Worbli JS libraries:

JS method signatures for both JS libraries:

  • get_blocks(onMessageHandler, onCloseHandler, onErrorHandler)
  • get_transaction(account, onMessageHandler, onCloseHandler, onErrorHandler)
  • get_actions(account, actions, onMessageHandler, onCloseHandler, onErrorHandler)
  • get_table_rows(account, table, scope, onMessageHandler, onCloseHandler, onErrorHandler)

Below is the sample use JS code for get_blocks method:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>Spectrum Demo</title>
  <script type=text/javascript src="https://spectrum-client.s3.amazonaws.com/telos.spectrum.min.js"></script>
  <script>
    var onMessageHandler = function (data) {
      console.log("Message: "+data);
    };
    var onCloseHandler = function(data) {
      console.log("Connection closed: "+data);
    };
    var onErrorHandler = function(error) {
      console.log("Error: "+error);
    };
    var websocket = get_blocks(onMessageHandler, onCloseHandler, onErrorHandler);
  </script>
</head>
<body>
  <p>View console for messages</p>
</body>
</html>

Sample JS code for get_transaction method:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>Spectrum Demo</title>
  <script type=text/javascript src="https://spectrum-client.s3.amazonaws.com/telos.spectrum.min.js"></script>
  <script>
    var onMessageHandler = function (data) {
      console.log("Message: "+data);
    };
    var onCloseHandler = function(data) {
      console.log("Connection closed: "+data);
    };
    var onErrorHandler = function(error) {
      console.log("Error: "+error);
    };
    var account = "eosio";
    var websocket = get_transaction(account, onMessageHandler, onCloseHandler, onErrorHandler);
  </script>
</head>
<body>
  <p>View console for messages</p>
</body>
</html>

Sample JS code for get_actions method:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>Spectrum Demo</title>
  <script type=text/javascript src="https://spectrum-client.s3.amazonaws.com/telos.spectrum.min.js"></script>
  <script>
    var onMessageHandler = function (data) {
      console.log("Message: "+data);
    };
    var onCloseHandler = function(data) {
      console.log("Connection closed: "+data);
    };
    var onErrorHandler = function(error) {
      console.log("Error: "+error);
    };
    var account = "eosio";
    var actions = ["transfer","buyram"];
    var websocket = get_actions(account, actions, onMessageHandler, onCloseHandler, onErrorHandler);
  </script>
</head>
<body>
  <p>View console for messages</p>
</body>
</html>

Feel free to give it a try and provide your feedback at out Telegram channel: https://t.me/EOSTribe

Original post describing Spectrum API architecture: https://steemit.com/eosio/@eostribe/introducing-spectrum-streaming-api-for-eosio

EOS Tribe is committed to continue work on creating innovative solutions for EOSIO.

Sort:  

Howdy! Spectrum has been our office's internet provider for over 5 years, and they've been consistently reliable. The internet speed aligns with our tariff plan, and any line damages are swiftly addressed by their skilled technicians, you can read more - https://spectrum.pissedconsumer.com/review.html . Interacting with their support representatives is always a pleasant experience; they are highly qualified and proactive in resolving any issues we encounter. Overall, Spectrum has been a dependable and responsive partner for our internet needs.

Coin Marketplace

STEEM 0.21
TRX 0.20
JST 0.033
BTC 97309.89
ETH 3288.22
USDT 1.00
SBD 2.99