-
Notifications
You must be signed in to change notification settings - Fork 46
/
electrum-connect-test.js
63 lines (51 loc) · 1.39 KB
/
electrum-connect-test.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const connect = require('./src/connect');
const electrumServers = require('./src/electrum-servers');
const network = require('./src/bitcoinjs-networks');
const { parseBlockToJSON } = require('./src/block');
const keyPair = require('./src/keyPair');
const server = electrumServers.rick.serverList[0].split(':');
const c = connect('electrum', { server: {ip: server[0], port: server[1], protocol: server[2] }});
const address = new keyPair('RNTv4xTLLm26p3SvsQCBy9qNK7s1RgGYSB', 'kmd');
const addressSH = address.toElectrumScriptHash();
(async function() {
c.getCurrentBlockNumber()
.then((res) => {
console.log(res);
});
await c.getServerVersion()
.then((res) => {
if (!res.error) {
c.setProtocolVersion(Number(res[1]));
console.log(c);
}
});
c.getTransaction('33a6c70c658ccf312ee55baddec0192695ba7ca098e4f58fe2ca3ee591a2740e', 530930)
.then((res) => {
console.log(res);
});
c.getBlockInfo(580285)
.then((res) => {
console.log(res);
});
// scripthash form
c.getBalance(addressSH)
.then((res) => {
console.log(res);
});
// scripthash form
c.getHistory(addressSH)
.then((res) => {
console.log(res);
});
// scripthash form
c.getUTXO(addressSH)
.then((res) => {
console.log(res);
});
c.getBlockInfo('1')
.then((res) => {
console.log(res);
res = parseBlockToJSON(res, network.kmd);
console.log(res);
});
})();