Constructor
new ElectrumClient(application, version, host, port, scheme, timeout, pingInterval)
Initializes an Electrum client.
Parameters:
Name | Type | Description |
---|---|---|
application |
string | your application name, used to identify to the electrum host. |
version |
string | protocol version to use with the host. |
host |
string | fully qualified domain name or IP number of the host. |
port |
number | the TCP network port of the host. |
scheme |
TransportScheme | the transport scheme to use for connection |
timeout |
number | how long network delays we will wait for before taking action, in milliseconds. |
pingInterval |
number | the time between sending pings to the electrum host, in milliseconds. |
Throws:
-
if `version` is not a valid version string.
- Type
- Error
Methods
(async) connect()
Connects to the remote server.
Throws:
-
if the socket connection fails.
- Type
- Error
Returns:
a promise resolving when the connection is established.
(async) disconnect(force, retainSubscriptions)
Disconnects from the remote server and removes all event listeners/subscriptions and open requests.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
force |
boolean |
false
|
disconnect even if the connection has not been fully established yet. |
retainSubscriptions |
boolean |
false
|
retain subscription data so they will be restored on reconnection. |
Returns:
true if successfully disconnected, or false if there was no connection.
(async) request(method, …parameters)
Calls a method on the remote server with the supplied parameters.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
method |
string | name of the method to call. | |
parameters |
string |
<repeatable> |
one or more parameters for the method. |
Throws:
-
if the client is disconnected.
- Type
- Error
Returns:
a promise that resolves with the result of the method or an Error.
(async) subscribe(callback, method, …parameters)
Subscribes to the method at the server and attaches the callback function to the event feed.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
callback |
function | a function that should get notification messages. | |
method |
string | one of the subscribable methods the server supports. | |
parameters |
string |
<repeatable> |
one or more parameters for the method. |
Throws:
-
if the client is disconnected.
- Type
- Error
Returns:
a promise resolving to true when the subscription is set up.
(async) unsubscribe(callback, method, …parameters)
Unsubscribes to the method at the server and removes any callback functions
when there are no more subscriptions for the method.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
callback |
function | a function that has previously been subscribed for this method. | |
method |
string | a previously subscribed to method. | |
parameters |
string |
<repeatable> |
one or more parameters for the method. |
Throws:
-
-
if no subscriptions exist for the combination of the passed `callback`, `method` and `parameters.
- Type
- Error
-
-
-
if the client is disconnected.
- Type
- Error
-
Returns:
a promise that resolves to true when the subscription has been cancelled.
Events
connected
Triggers when the underlying connection is established.
disconnected
Triggers when the underlying connection is lost.