forked from gemlink/electrum-client-ts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
subscribe.js
32 lines (23 loc) · 910 Bytes
/
subscribe.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 ElectrumClient = require('..')
const sleep = (ms) => new Promise((resolve, _) => setTimeout(() => resolve(), ms))
const main = async () => {
try {
const ecl = new ElectrumClient('fortress.qtornado.com', 50002, 'tls')
ecl.subscribe.on('blockchain.headers.subscribe', console.log)
ecl.subscribe.on('blockchain.scripthash.subscribe', console.log)
await ecl.connect()
const header = await ecl.blockchain_headers_subscribe()
console.log('Latest header:', header)
const scripthashStatus = await ecl.blockchain_scripthash_subscribe('f3aa57a41424146327e5c88c25db8953dd16c6ab6273cdb74a4404ed4d0f5714')
console.log('Latest scripthash status:', scripthashStatus)
console.log('Waiting for notifications...')
while (true) {
// Keep connection alive.
await sleep(1000)
await ecl.server_ping()
}
} catch (e) {
console.error(e)
}
}
main()