Created
July 29, 2022 19:26
-
-
Save atmoner/09ce804a7791b8f03a9d9bc4584e47eb to your computer and use it in GitHub Desktop.
Akash WebSocket
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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
🔥