forked from mempool/mempool.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
websocket.ts
38 lines (27 loc) · 1.01 KB
/
websocket.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import mempoolJS from "./../../../src/index";
const init = async () => {
try {
const { liquid: { websocket } } = mempoolJS( { hostname: 'liquid.network' } );
const ws = websocket.wsInit();
ws.addEventListener('message', function incoming({data}) {
console.log(JSON.parse(data.toString()));
});
websocket.wsWantData(ws, ['blocks', 'stats', 'mempool-blocks', 'live-2h-chart']);
websocket.wsTrackAddress(ws, "GiAi95k5JUPNPoDGNzSUZ8vWMijSiSMTon");
websocket.wsTrackAddresses(ws, [
"GsDhxpV4Voi3XJA22bnAH4q8117hjZrQMF",
]);
websocket.wsTrackTransaction(ws, "23195d459a70875c3b1f9fb9082acc9f0594f1c63dac71b40f2ff7298630a421");
websocket.wsTrackMempoolBlock(ws, 1);
setTimeout(() => {
websocket.wsStopData(ws);
websocket.wsStopTrackingAddress(ws);
websocket.wsStopTrackingAddresses(ws);
websocket.wsStopTrackingTransaction(ws);
websocket.wsStopTrackingMempoolBlock(ws);
}, 60000);
} catch (error) {
console.log(error);
}
}
init();