From 9590ca5762ddf004b6d11f00b9983d07d4c13983 Mon Sep 17 00:00:00 2001 From: you21979 Date: Mon, 10 Jul 2017 20:34:30 +0900 Subject: [PATCH] add example --- example/subscribe.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 example/subscribe.js diff --git a/example/subscribe.js b/example/subscribe.js new file mode 100644 index 0000000..687e940 --- /dev/null +++ b/example/subscribe.js @@ -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()