-
Notifications
You must be signed in to change notification settings - Fork 1
/
electrum.js
46 lines (38 loc) · 1.28 KB
/
electrum.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const electrumclient = require('electrum-client')
const Client = electrumclient.Client
// version control interface
const ElectrumProtocol = electrumclient.v1.ElectrumProtocol
const proc = async (ecl) => {
const balance = await ecl.blockchain_address_getBalance("12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX")
console.log(balance)
const unspent = await ecl.blockchain_address_listunspent("12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX")
console.log(unspent)
const tx1 = await ecl.blockchain_transaction_get("f91d0a8a78462bc59398f2c5d7a84fcff491c26ba54c4833478b202796c8aafd")
console.log(tx1)
}
const main = async () => {
// autogenerate client name
const myname = [ElectrumProtocol.libname, ElectrumProtocol.hash].join('-')
console.log(myname)
// initialize
const ecl = new ElectrumProtocol(new Client(10059, 'electrum1.cipig.net', 'tcp'))
// wait a connection
await ecl.client.connect()
try{
// negotiation protocol
const res = await ecl.server_version(myname)
console.log(res)
}catch(e){
// negotiation error
await ecl.client.close()
console.log(e)
return;
}
try{
await proc(ecl)
}catch(e){
console.log(e)
}
await ecl.client.close()
}
main().catch(console.log)