forked from itzmeanjan/ette
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransaction_2.js
32 lines (21 loc) · 928 Bytes
/
transaction_2.js
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
const { client } = require('websocket')
const _client = new client()
let state = true
_client.on('connectFailed', e => { console.error(`[!] Failed to connect : ${e}`); process.exit(1); })
// For outgoing tx(s) from account
_client.on('connect', c => {
c.on('close', d => {
console.log(`[!] Closed connection : ${d}`)
process.exit(0)
})
c.on('message', d => { console.log(JSON.parse(d.utf8Data)) })
handler = _ => {
// from address is specified, any tx outgoing from account `0x...`
// can be listened using this topic
c.send(JSON.stringify({ name: 'transaction/0x4774fEd3f2838f504006BE53155cA9cbDDEe9f0c/*', type: state ? 'subscribe' : 'unsubscribe', apiKey: '0x43ee4523fc8cc569b492fcda6f32e07d90d2afdf7a8a02b5e74c933be1785487' }))
state = !state
}
setInterval(handler, 10000)
handler()
})
_client.connect('ws://localhost:7000/v1/ws', null)