Skip to content

Commit

Permalink
add example
Browse files Browse the repository at this point in the history
  • Loading branch information
you21979 committed Jul 10, 2017
1 parent 0ac3165 commit 9590ca5
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions example/subscribe.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const ElectrumClient = require('..')
const sleep = (ms) => new Promise((resolve,_) => setTimeout(() => resolve(ms), ms))

const main = async () => {
const ecl = new ElectrumClient(995, 'btc.smsys.me', 'tls')
ecl.subscribe.on('server.peers.subscribe', console.log)
ecl.subscribe.on('blockchain.numblocks.subscribe', console.log)
ecl.subscribe.on('blockchain.headers.subscribe', console.log)
await ecl.connect()
const p1 = await ecl.serverPeers_subscribe()
const p2 = await ecl.blockchainHeaders_subscribe()
const p3 = await ecl.blockchainNumblocks_subscribe()
while(true){
await sleep(1000)
}
await ecl.close()
}
main()

0 comments on commit 9590ca5

Please sign in to comment.