ElectrumClient

ElectrumClient

High-level Electrum client that lets applications send requests and subscribe to notification events from a server.

Constructor

new ElectrumClient(application, version, host, port, scheme, timeout, pingInterval, reconnectInterval, useBigInt)

Description:
  • 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.
reconnectInterval number the time between reconnection attempts to the electrum host, in milliseconds.
useBigInt boolean whether to use bigint for numbers in json response.
Throws:
if `version` is not a valid version string.
Type
Error

Classes

ElectrumClient

Methods

(async) connect()

Description:
  • Connects to the remote server.
Throws:
if the socket connection fails.
Type
Error
Returns:
a promise resolving when the connection is established.

(async) connect()

Description:
  • 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)

Description:
  • 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) disconnect(force, retainSubscriptions)

Description:
  • Disconnects from the remote server and removes all event listeners/subscriptions and open requests.
Parameters:
Name Type Description
force boolean disconnect even if the connection has not been fully established yet.
retainSubscriptions boolean 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)

Description:
  • 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) request(method, …parameters)

Description:
  • 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(method, …parameters)

Description:
  • Subscribes to the method and payload at the server.
Parameters:
Name Type Attributes Description
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 when the subscription is established.

(async) subscribe(method, …parameters)

Description:
  • Subscribes to the method and payload at the server.
Parameters:
Name Type Attributes Description
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 when the subscription is established.

(async) unsubscribe(method, …parameters)

Description:
  • 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
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 provided `method` and `parameters.
    Type
    Error
  • if the client is disconnected.
    Type
    Error
Returns:
a promise resolving when the subscription is removed.

(async) unsubscribe(method, …parameters)

Description:
  • 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
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 provided `method` and `parameters.
    Type
    Error
  • if the client is disconnected.
    Type
    Error
Returns:
a promise resolving when the subscription is removed.

Events

connected

Description:
  • Triggers when the underlying connection is established.

disconnected

Description:
  • Triggers when the underlying connection is lost.

notification

Description:
  • Triggers when the remote server sends data that is not a request response.