Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
xrpl-client
Advanced tools
xrpl-client
Auto reconnecting, buffering, subscription remembering XRP Ledger WebSocket client. For in node & the browser.
This client implements a check for a working XRPL connection: the WebSocket being simply online isn't enough to satisfy the online / offline detection of this lib. After connecting, this lib. will issue a server_info
command to the other connected node. Only if a valid response is retrieved the connection will be marked as online.
A client connection can be constructed with the exported XrplClient
class:
import { XrplClient } from "xrpl-client";
const client = new XrplClient();
// ^^ No arguments: defaults to one endpoint:
// ['wss://xrplcluster.com', 'wss://xrpl.link', 'wss://s2.ripple.com']
// with `maxConnectionAttempts` option `null` (= try forever)
If no argument is provided, the default endpoint this lib. will connect to is wss://xrplcluster.com
, wss://xrpl.link (fallback) and finally wss://s2.ripple.com. Alternatively, two arguments can be provided:
string
, or an array (string[]
) with multiple endpoints used in specified order. Empty string or array if you want to use the default nodes, but specify custom options using the second param.:Available options are:
assumeOfflineAfterSeconds
, Number
» default 150, this setting will check if the XRPL node on the other end of the connection is alive and sending regular server_info
responses (this lib. queries for them). After the timeout, the lib. will disconnect from the node and try to reconnect.maxConnectionAttempts
, Number
| null
» default null in case of one endpoint, or 3 if an array with endpoints is provided, if (when initially connecting or reconnecting) no (new) connection could be setup in this attempts (see: connectAttemptTimeoutSeconds
per call) consider the connection dead. Cancel all connect/reconnect attempts, clear the command buffer. An error will be thrown.connectAttemptTimeoutSeconds
, Number
» default 3, this setting is the max. delay between reconnect attempts, if no connection could be setup to the XRPL node. A backoff starting at one second, growing with 20% per attempt until this value is reached will be used.Sample with a custom node & option:
import { XrplClient } from "xrpl-client";
const client = new XrplClient(
["ws://localhost:1337", "wss://xrplcluster.com"],
{
assumeOfflineAfterSeconds: 15,
maxConnectionAttempts: 4,
connectAttemptTimeoutSeconds: 4,
}
);
send({ command: "..."}, {SendOptions})
» Promise<AnyJson | CallResponse>
» Send a comand
to the connected XRPL node.ready()
» Promise<self>
» fires when you're fully connected. While the state
event (and getState()
method) only return the WebSocket online state, ready()
will only return (async) if the first ledger data has been received and the last ledger index is known.getState()
» ConnectionState
» Get the connection, connectivity & server state (e.g. fees, reserves).void
» Fully close the entire object (can't be used again).The send({ comand: "..." })
method allows you to set these options (second argument, object):
timeoutSeconds
, Boolean
» The returned Promise will be rejected if a response hasn't been received within this amount of seconds. This timeout starts when the command is issued by your code, no matter the connection state (online or offline, possibly waiting for a connecftion)timeoutStartsWhenOnline
, Number
» The timeout (see timeoutSeconds
) will start when the connection has been marked online (WebSocket connected, server_info
received from the XRPL node), so when your command has been issued by this lib. to the XRPL node on the other end of the connection.sendIfNotReady
, Boolean
» Your commands will be sent to the XRPL node on the other end of the connection only when the connection has been marked online (WebSocket connected, server_info
received from the XRPL node). Adding this option (true
) will send your commands after the WebSocket has been connected, but possibly before a valid server_info
response has been received by the XRPL node connected to.noReplayAfterReconnect
, Boolean
» When adding a subscription (resulting in async. updates) like a subscribe
or path_find
command, when reconnected your subscription commands will automaticaly replay to the newly connected node. Providing a false
to this option will prevent your commands from being replayed when reconnected.state
(the state of the connection changed from online to offline or vice versa)message
(all messages, even if duplicate of the ones below)ledger
(a ledger closed)path
(async path_find
response)transaction
validation
retry
(new connection attempt)close
(upstream closed the connection)reconnect
(reconnecting, after connected: state
)retry
- Same node, new connection attempt (attempt timed out)nodeswitch
» string (node) - Switched to a new nodeonline
» Now conneted to an XRPL node, use .getState()
for more infooffline
» Was online, but the connection is goneround
» Tried all nodes, retry the first oneLet's say you have two dead endpoints and a third one that works, then your connection is lost and you switch to the fourth one. The event sequence would look like this:
1. retry » 2. retry » 3. retry » 4. nodeswitch
5. retry » 6. retry » 7. retry » 8. nodeswitch
9. online
10. offline
11. retry » 12. retry » 13. retry » 14. nodeswitch
15. online
import { XrplClient } from "xrpl-client";
const client = new XrplClient("wss://xrplcluster.com");
// await client.ready();
const serverInfo = await client.send({ command: "server_info" });
console.log({ serverInfo });
client.on("ledger", (ledger) => {
console.log("Ledger", ledger);
});
You can clone this repository and run:
npm run install
to install dependenciesnpm run build
to build the source codenpm run browserify
to browserify this lib.Now the dist/browser.js
file will exist, for you to use in a browser.
Alternatively you can get a prebuilt / prebuilt & minified version from Github.
Sample: https://jsfiddle.net/WietseWind/p4cd37hf
rippled-ws-client
await TheObject.ready()
and then refer to TheObject
:// Old:
// new RippledWsClient('wss://testnet.xrpl-labs.com').then(Connection => { ... })
// New:
const Connection = new RippledWsClient('wss://testnet.xrpl-labs.com')
Connection.ready().then(() => {
rippled-ws-client-sign
(please use xrpl-accountlib
instead!) you need to wrap the class:class RippledWsClient extends XrplClient {} // Then use RippledWsClient
FAQs
Connect to the XRP Ledger using WebSockets
The npm package xrpl-client receives a total of 551 weekly downloads. As such, xrpl-client popularity was classified as not popular.
We found that xrpl-client demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.