Getting Started
Watchtower uses Websockets to stream down data from the Mirror Node.
For integration we will use a standard library Socket.io.
info
You will need:
- Arkhia Watchtower URL
- Arkhia API_KEY
Both the URL and API KEY can be retrieved from the Arkhia Dashboard after you Create a Project.
Don't have an account yet with Arkhia? Signup.
Connect to Watchtower and make sure all is running. Make sure you install socket.io package before by running:
npm install socket.io npm install socket.io-client (frontend apps)
- React.js
- Node.js
- HTML/Javascript
import React, { useEffect, useState } from "react";import io from 'socket.io-client';function StreamingInit () { const watchtowerURL = `https://<WATCHTOWER_URL>?api_key=<ARKHIA_API_KEY>`; const socket = io(watchtowerURL, { transports: ['websocket'] }); const [socketStatus, setSocketStatus] = useState(``); useEffect(() => { socket.on(`connect`, () => { socket.on(`status`, (msg) => { console.log(`status`, msg); setSocketStatus(`Watchtower is successfully connected`); }); socket.emit(`list-services`, (services: any) => { console.log(`Listing available services`, services); }); }); socket.on(`disconnect`, (msg: any) => { setSocketStatus(`Watchtower is disconnected.`) console.log(`Disconnected.`) }); socket.on(`error`, (message: any) => { console.error(message); setSocketStatus(message) }) }, [socket]); return ( <> <div> { socketStatus && ( <> <h6>Watchtower status</h6> <div>{socketStatus}</div> </> ) } </div> </> );}export default StreamingInit;
const io = require('socket.io-client');const watchtowerURL = `https://<WATCHTOWER_URL>?api_key=<ARKHIA_API_KEY>`;const socket = io(watchtowerURL, { transports: ['websocket']});socket.on(`connect`, () => { socket.on(`status`, (msg) => { console.log(`Watchtower is successfully connected`); console.log(`status`, msg); }); socket.emit(`list-services`, (services) => { console.log(`Listing available services`, services); });});socket.on(`disconnect`, (msg) => { console.log(`Watchtower is disconnected.`) console.log(`Disconnected.`)});socket.on(`error`, (message) => { console.error(message); console.log(message)})
https://watchtowerws.mainnet.arkhia.io/?api_key={YOUR_API_KEY}
<!DOCTYPE html><html><head> <style> body { margin: 0; padding-bottom: 3rem; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; } #messages { list-style-type: none; margin: 0; padding: 0; } #messages>li { padding: 0.5rem 1rem; background: #868484; } #messages>li:nth-child(odd) { background: #efefef; } </style></head><body> <ul id="messages"></ul></body><script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.5.4/socket.io.min.js"></script><script> const watchtowerURL = `wss://<WATCHTOWER_URL>?api_key=<ARKHIA_API_KEY>`; const socket = io(watchtowerURL); socket.on('connect', function () { socket.on('status', (msg) => { console.log('status', msg); addMessage('status', msg); }); socket.emit('list-services', function (services) { console.log('services', services); addMessage('services', services); }) }); function addMessage(event, message) { var item = document.createElement('li'); item.innerHTML = `` messages.appendChild(item); window.scrollTo(0, document.body.scrollHeight); }</script></html>
info
At this moment, if you have a Growth account with the right config you should have a successfull connection.