Spectrum API - NodeJS client code example

in #spectrum5 years ago

spectrum.jpeg

NodeJS client code example for Telos Testnet

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://testnet.telos.eostribe.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()

Assuming code above is saved in index.html, one can run above code by executing following commands:

npm install node-fetch
node index.js

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

See more posts about Spectrum API on SteemIt: https://steemit.com/@eostribe/

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

Sort:  

Congratulations @eostribe! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

You published more than 100 posts. Your next target is to reach 150 posts.

You can view your badges on your Steem Board and compare to others on the Steem Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

To support your work, I also upvoted your post!

Do not miss the last post from @steemitboard:

SteemFest⁴ - Meet the Steemians Contest
Vote for @Steemitboard as a witness to get one more award and increased upvotes!

Hey there! When it comes to choosing a telecommunications service provider, you want a company you can trust to provide reliable services, cutting-edge technology, and excellent customer support. Telecommunications service provider Spectrum offers all this and more. Users constantly write about the high quality of the company's services in reviews here https://spectrum.pissedconsumer.com/review.html from which we can conclude that this company will never let you down, and you can rely on it.