-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.ts
26 lines (25 loc) · 1011 Bytes
/
script.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
const WebSocket = require("ws");
const ws = new WebSocket("ws://localhost:10500");
ws.on("open", () => {
ws.send(`{ "jsonrpc": "2.0", "id": 1, "method": "eth_subscribe", "params": ["newPendingTransactions"] }`, (err, result) => {
console.log("ERRRO : " + err);
console.log("DATA : " + result);
});
// ws.send(`{ "jsonrpc": "2.0", "id": 1, "method": "eth_subscribe", "params": ["newHeads"] }`, (err, result) => {
// console.log("ERRRO : " + err);
// console.log("DATA : " + result);
// });
ws.on("message", (data) => {
console.log("data : " + data);
console.log("Type " + typeof data);
const result = JSON.parse(data);
if (result.params) {
const res = result.params.result;
console.log("res = " + res);
}
});
ws.on("error", (err) => {
console.log("ERROR : " + err);
process.exit(0);
});
});