Skip to content

Instantly share code, notes, and snippets.

@andy108369
Forked from atmoner/app.js
Created August 20, 2022 14:48
Show Gist options
  • Save andy108369/97f071dcb7fffcdc3e075d48930b71a5 to your computer and use it in GitHub Desktop.
Save andy108369/97f071dcb7fffcdc3e075d48930b71a5 to your computer and use it in GitHub Desktop.
Akash WebSocket
import WebSocket from 'ws';
const ws = new WebSocket('wss://rpc-akash-ia.notional.ventures/websocket');
ws.on('open', function open() {
console.log('Connected on Akash blockchain from WebSocket');
ws.send(JSON.stringify({
"method":"subscribe",
"params": ["tm.event='NewBlock'"],
"id":"1",
"jsonrpc":"2.0"
}));
});
ws.on('close', function close() {
console.log('disconnected');
});
ws.on('message', function incoming(data) {
var finalData = JSON.parse(data.toString('utf-8'));
if (finalData.result.data)
console.log(finalData.result);
});
{
"name": "akash-websocket",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"keywords": [],
"author": "atmon3r",
"license": "ISC",
"dependencies": {
"ws": "^8.8.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment