@electrum-cash/network 4.0.0-development.6391574314 → 4.0.0-development.6393041663
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -59
- package/dist/index.d.ts +0 -33
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +140 -167
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -5
package/README.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Introduction
|
|
2
|
+
|
|
3
|
+
@electrum-cash/network is a lightweight `JavaScript` library that lets you connect `Electrum` servers.
|
|
2
4
|
|
|
3
|
-
Electrum-cash is a lightweight `JavaScript` library that lets you connect with one or more `Electrum` servers.
|
|
4
5
|
It offers encrypted connections by default,
|
|
5
6
|
performs the expected protocol version negotiation and
|
|
6
7
|
automatically keeps your connection alive until your close it.
|
|
@@ -10,7 +11,7 @@ automatically keeps your connection alive until your close it.
|
|
|
10
11
|
Install the library with NPM:
|
|
11
12
|
|
|
12
13
|
```bash
|
|
13
|
-
# npm install electrum-cash
|
|
14
|
+
# npm install @electrum-cash/network
|
|
14
15
|
```
|
|
15
16
|
|
|
16
17
|
## Usage
|
|
@@ -19,18 +20,9 @@ Install the library with NPM:
|
|
|
19
20
|
|
|
20
21
|
Before you can use the library you need to include it in your project.
|
|
21
22
|
|
|
22
|
-
If you only want to use a **single server**, load the `ElectrumClient` module:
|
|
23
|
-
|
|
24
|
-
```js
|
|
25
|
-
// Load the electrum library.
|
|
26
|
-
const { ElectrumClient } = require('electrum-cash');
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
If you want to use **multiple servers**, load the `ElectrumCluster` module:
|
|
30
|
-
|
|
31
23
|
```js
|
|
32
24
|
// Load the electrum library.
|
|
33
|
-
const {
|
|
25
|
+
const { ElectrumClient } = require('@electrum-cash/network');
|
|
34
26
|
```
|
|
35
27
|
|
|
36
28
|
### Usage on Web
|
|
@@ -39,54 +31,33 @@ To use the library on the web, use the ESM import syntax and include the `Electr
|
|
|
39
31
|
|
|
40
32
|
```js
|
|
41
33
|
// Load the electrum library.
|
|
42
|
-
import { ElectrumClient, ElectrumTransport } from 'electrum-cash';
|
|
34
|
+
import { ElectrumClient, ElectrumTransport } from '@electrum-cash/network';
|
|
43
35
|
```
|
|
44
36
|
|
|
45
|
-
###
|
|
37
|
+
### Connecting to a server
|
|
46
38
|
|
|
47
|
-
After you have
|
|
39
|
+
After you have imported the library you need to initialize and connect the client by configuring your **application identifier** and **protocol version**.
|
|
48
40
|
|
|
49
|
-
If you only want to use a single server, initialize an `ElectrumClient` and connect to the server:
|
|
50
41
|
```js
|
|
51
42
|
// Initialize an electrum client.
|
|
52
|
-
const
|
|
43
|
+
const electrumClient = new ElectrumClient('Electrum client example', '1.4.1', 'bch.imaginary.cash');
|
|
53
44
|
|
|
54
45
|
// Wait for the client to connect
|
|
55
|
-
await
|
|
46
|
+
await electrumClient.connect();
|
|
56
47
|
```
|
|
57
48
|
|
|
58
49
|
To connect to an electrum server from a web browser, use the `ElectrumTransport` import to use the WSS `port` and `scheme`:
|
|
59
50
|
|
|
60
51
|
```js
|
|
61
|
-
const
|
|
52
|
+
const electrumClient = new ElectrumClient(
|
|
62
53
|
'Electrum client example', '1.4.1', 'bch.imaginary.cash',
|
|
63
54
|
ElectrumTransport.WSS.Port, ElectrumTransport.WSS.Scheme
|
|
64
55
|
);
|
|
65
56
|
```
|
|
66
57
|
|
|
67
|
-
If you want to use multiple servers, initialize an `ElectrumCluster` and add some servers:
|
|
68
|
-
|
|
69
|
-
*For more information on various cluster configurations, read the [cluster documentation](https://read.cash/@JonathanSilverblood/electrum-cash-strategic-use-of-clusters-83743111).*
|
|
70
|
-
|
|
71
|
-
```js
|
|
72
|
-
// Initialize an electrum cluster where 2 out of 3 needs to be consistent, polled randomly with fail-over (default).
|
|
73
|
-
const electrum = new ElectrumCluster('Electrum cluster example', '1.4.1', 2, 3);
|
|
74
|
-
|
|
75
|
-
// Add some servers to the cluster.
|
|
76
|
-
electrum.addServer('bch.imaginary.cash');
|
|
77
|
-
electrum.addServer('electroncash.de');
|
|
78
|
-
electrum.addServer('electroncash.dk');
|
|
79
|
-
electrum.addServer('electron.jochen-hoenicke.de', 51002);
|
|
80
|
-
electrum.addServer('electrum.imaginary.cash');
|
|
81
|
-
|
|
82
|
-
// Wait for enough connections to be available.
|
|
83
|
-
await electrum.ready();
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
|
|
87
58
|
### Request information
|
|
88
59
|
|
|
89
|
-
Once your `ElectrumClient`
|
|
60
|
+
Once your `ElectrumClient` is connected and ready, you can call methods:
|
|
90
61
|
|
|
91
62
|
*For a list of methods you can use, refer to the [Electrum Cash documentation](https://bitcoincash.network/electrum/).*
|
|
92
63
|
|
|
@@ -95,7 +66,7 @@ Once your `ElectrumClient` or `ElectrumCluster` is connected and ready, you can
|
|
|
95
66
|
const transactionID = '4db095f34d632a4daf942142c291f1f2abb5ba2e1ccac919d85bdc2f671fb251';
|
|
96
67
|
|
|
97
68
|
// Request the full transaction hex for the transaction ID.
|
|
98
|
-
const transactionHex = await
|
|
69
|
+
const transactionHex = await electrumClient.request('blockchain.transaction.get', transactionID);
|
|
99
70
|
|
|
100
71
|
// Print out the transaction hex.
|
|
101
72
|
console.log(transactionHex);
|
|
@@ -103,7 +74,7 @@ console.log(transactionHex);
|
|
|
103
74
|
|
|
104
75
|
### Subscribe to notifications.
|
|
105
76
|
|
|
106
|
-
Once your `ElectrumClient`
|
|
77
|
+
Once your `ElectrumClient` is connected and ready, you can set up subscriptions to get notifications on events:
|
|
107
78
|
|
|
108
79
|
*For a list of methods you can subscribe to, refer to the [Electrum Cash documentation](https://bitcoincash.network/electrum/).*
|
|
109
80
|
|
|
@@ -130,40 +101,29 @@ const handleNotifications = function(data)
|
|
|
130
101
|
}
|
|
131
102
|
|
|
132
103
|
// Listen for notifications.
|
|
133
|
-
|
|
104
|
+
electrumClient.on('notification', handleNotifications);
|
|
134
105
|
|
|
135
106
|
// Set up a subscription for new block headers.
|
|
136
|
-
await
|
|
107
|
+
await electrumClient.subscribe('blockchain.headers.subscribe');
|
|
137
108
|
```
|
|
138
109
|
|
|
139
110
|
### Shutting down
|
|
140
111
|
|
|
141
|
-
When you're done and don't want to be connected anymore you can disconnect the server
|
|
142
|
-
|
|
143
|
-
If you're using a single `ElectrumClient`, call the `disconnect()` function:
|
|
112
|
+
When you're done and don't want to be connected anymore you can disconnect the server:
|
|
144
113
|
|
|
145
114
|
```js
|
|
146
115
|
// Close the connection.
|
|
147
|
-
await
|
|
148
|
-
```
|
|
149
|
-
|
|
150
|
-
If you're using a `ElectrumCluster` with multiple servers, call the `shutdown()` function.
|
|
151
|
-
|
|
152
|
-
```js
|
|
153
|
-
// Close all connections.
|
|
154
|
-
await electrum.shutdown();
|
|
116
|
+
await electrumClient.disconnect();
|
|
155
117
|
```
|
|
156
118
|
|
|
157
119
|
## Documentation
|
|
158
120
|
|
|
159
|
-
For a complete list of methods and parameters, read the [API documentation](https://
|
|
121
|
+
For a complete list of methods and parameters, read the [API documentation](https://electrum-cash.gitlab.io/network/).
|
|
160
122
|
|
|
161
123
|
## Support and communication
|
|
162
124
|
|
|
163
125
|
If you need help with how to use the library or just want to talk about electrum-cash, you can find us on [Telegram](https://t.me/electrumcash) and [Discord](https://discord.gg/ZjXQzew).
|
|
164
126
|
|
|
165
|
-
You can also read our tutorials on [read.cash](https://read.cash/c/electrum-cash-f45e), or share your own.
|
|
166
|
-
|
|
167
127
|
## Notes
|
|
168
128
|
|
|
169
129
|
The keep-alive functionality of this library only works when the protocol version is 1.2 or higher.
|
package/dist/index.d.ts
CHANGED
|
@@ -21,36 +21,6 @@ interface RPCErrorResponse extends RPCBase {
|
|
|
21
21
|
error: RPCError;
|
|
22
22
|
}
|
|
23
23
|
type RPCResponse = RPCErrorResponse | RPCStatement;
|
|
24
|
-
/**
|
|
25
|
-
* Enum that denotes the ordering to use in an ElectrumCluster.
|
|
26
|
-
* @enum {number}
|
|
27
|
-
* @property {0} RANDOM Send requests to randomly selected servers in the cluster.
|
|
28
|
-
* @property {1} PRIORITY Send requests to servers in the cluster in the order they were added.
|
|
29
|
-
*/
|
|
30
|
-
export enum ClusterOrder {
|
|
31
|
-
RANDOM = 0,
|
|
32
|
-
PRIORITY = 1
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Enum that denotes the distribution setting to use in an ElectrumCluster.
|
|
36
|
-
* @enum {number}
|
|
37
|
-
* @property {0} ALL Send requests to all servers in the cluster.
|
|
38
|
-
*/
|
|
39
|
-
export enum ClusterDistribution {
|
|
40
|
-
ALL = 0
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Enum that denotes the ready status of an ElectrumCluster.
|
|
44
|
-
* @enum {number}
|
|
45
|
-
* @property {0} DISABLED The cluster is disabled and unusable.
|
|
46
|
-
* @property {1} DEGRADED The cluster is degraded but still usable.
|
|
47
|
-
* @property {2} READY The cluster is healthy and ready for use.
|
|
48
|
-
*/
|
|
49
|
-
export enum ClusterStatus {
|
|
50
|
-
DISABLED = 0,
|
|
51
|
-
DEGRADED = 1,
|
|
52
|
-
READY = 2
|
|
53
|
-
}
|
|
54
24
|
/**
|
|
55
25
|
* Enum that denotes the availability of an ElectrumClient.
|
|
56
26
|
* @enum {number}
|
|
@@ -138,9 +108,6 @@ export const DefaultParameters: {
|
|
|
138
108
|
RECONNECT: number;
|
|
139
109
|
TIMEOUT: number;
|
|
140
110
|
PING_INTERVAL: number;
|
|
141
|
-
CLUSTER_CONFIDENCE: number;
|
|
142
|
-
CLUSTER_DISTRIBUTION: ClusterDistribution;
|
|
143
|
-
CLUSTER_ORDER: ClusterOrder;
|
|
144
111
|
USE_BIG_INT: boolean;
|
|
145
112
|
};
|
|
146
113
|
/**
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";ACCA,oBAA2B,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CA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,GAAG,OAAO,CAAC,IAAI,CAAC;IA6E/E;;;;;;;OAOG;IACH,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,WAAW,GAAG,IAAI;IAiDtD;;;;;OAKG;IACH,sBAAsB,IAAI,IAAI;CAkB9B","sources":["source/source/util.ts","source/source/rpc-interfaces.ts","source/source/electrum-protocol.ts","source/source/enums.ts","source/source/interfaces.ts","source/source/constants.ts","source/source/electrum-socket.ts","source/source/electrum-connection.ts","source/source/electrum-client.ts","source/source/index.ts","source/index.ts"],"sourcesContent":[null,null,null,null,null,null,null,null,null,null,"export { default as ElectrumClient } from './electrum-client';\n\nexport * from './interfaces';\nexport * from './constants';\nexport * from './enums';\n"],"names":[],"version":3,"file":"index.d.ts.map"}
|