Published: 15 Oct 2019 › Updated: 15 Oct 2019
Spectrum API - Client JS samples
EOS Tribe launched a beta version of it's web-socket streaming Spectrum API on Telos Testnet (https://www.telosfoundation.io/).
Telos Testnet Spectrum API web-socket endpoint: wss://testnet.telos.eostribe.io
Sample HTML/JS Client code for Get Actions:
<html>
<head><title>Spectrum Web Sockets</title>
<script>
let socket = new WebSocket("wss://testnet.telos.eostribe.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) {
var divLog = document.getElementById("log");
divLog.innerHTML += ""
+data+"";
}
</script>
</head>
<body>
<h2>Spectrum Web Sockets Test: Get Actions</h2>
<div id="log"></div>
</body>
Sample HTML/JS Client code for Get Blocks:
<html>
<head><title>Spectrum Web Sockets</title>
<script>
let socket = new WebSocket("wss://testnet.telos.eostribe.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) {
var divLog = document.getElementById("log");
divLog.innerHTML += ""
+data+"";
}
</script>
</head>
<body>
<h2>Spectrum Web Sockets Test: Get Blocks</h2>
<div id="log"></div>
</body>
Sample HTML/JS Client code for Get Transaction:
<html>
<head><title>Spectrum Web Sockets</title>
<script>
let socket = new WebSocket("wss://testnet.telos.eostribe.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) {
var divLog = document.getElementById("log");
divLog.innerHTML += ""
+data+"";
}
</script>
</head>
<body>
<h2>Spectrum Web Sockets Test: Get Transactions</h2>
<div id="log"></div>
</body>
See a working example on EOS Tribe website: https://eostribe.io
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.
Leave Spectrum API - Client JS samples to:
Read more #spectrum posts
Best Posts From EOS Tribe
We have not curated any of eostribe's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.
More Posts From EOS Tribe
- EOS Tribe joins the WAX Network
- EOS Tribe + EOS USA launch Spectrumeos.io
- EOS Tribe + EOS USA are bringing Spectrum API + Full History API to EOS
- Spectrum API - NodeJS client code example
- Spectrum API - JS Client library with samples
- Spectrum API - Added get_table_rows endpoint
- Spectrum API running on Telos Mainnet
- Spectrum API - get_transaction endpoint available
- Spectrum API - Client JS samples
- Spectrum API running on Telos Testnet
- Spectrum API running on Telos Testnet
- Introducing Spectrum Streaming API for EOSIO
- My reflection on EOS history and current state
- New way to create EOS accounts without any upfront cost
- Easy New Account Creation Process for EOS, BOS, Telos and Meet.One
- KIBISIS Wallet adds support for Meet.One chain
- Kibisis Wallet Update - June 2019
- EOS Tribe open source swift-ecc library
- EOS Tribe announces partnership with StrongBlock
- Kibisis Wallet now available on App Store