### XRPL Client Basic Syntax and Event Handling Source: https://github.com/xrpl-labs/xrpl-client/blob/main/README.md Demonstrates the basic syntax for initializing the XRPL client, sending a 'server_info' command, and subscribing to 'ledger' events. It requires the 'xrpl-client' library. ```typescript 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); }); ``` -------------------------------- ### Migrating from rippled-ws-client to XRPL Client Source: https://github.com/xrpl-labs/xrpl-client/blob/main/README.md Provides guidance on migrating from the older 'rippled-ws-client' to the new 'xrpl-client'. It highlights changes in constructor behavior and demonstrates how to ensure a live connection using '.ready()'. ```javascript // Old: // new RippledWsClient('wss://testnet.xrpl-labs.com').then(Connection => { ... }) // New: const Connection = new RippledWsClient('wss://testnet.xrpl-labs.com') Connection.ready().then(() => { ``` -------------------------------- ### Client Initialization and Options Source: https://github.com/xrpl-labs/xrpl-client/blob/main/README.md This section outlines the options available when initializing the XrplClient, which control connection behavior, timeouts, and fee handling. ```APIDOC ## Client Initialization and Options ### Description Configure the XrplClient with various options to customize connection behavior, timeouts, and fee thresholds. ### Options - **assumeOfflineAfterSeconds** (Number) - Default: `15`. Sets the time after which a node is considered offline if no `server_info` responses are received. The client will attempt to reconnect. - **maxConnectionAttempts** (Number | null) - Default: `null` (single endpoint) or `3` (multiple endpoints). The maximum number of connection attempts before considering the connection dead and throwing an error. - **connectAttemptTimeoutSeconds** (Number) - Default: `3`. The maximum delay between connection re-attempts. A backoff strategy is employed, starting at one second and increasing by 20% per attempt, up to this value. - **feeDropsDefault** (Number) - Default: `12`. The minimum transaction fee (in drops) reported by the node to be considered for the `getState()` reported average fee. - **feeDropsMax** (Number) - Default: `3600`. The maximum transaction fee (in drops) reported by the node to be considered for the `getState()` reported average fee. - **tryAllNodes** (Boolean) - Default: `false`. If `true`, connection attempts are made to all provided nodes simultaneously, connecting to the first one that responds. ### Request Example ```typescript import { XrplClient } from "xrpl-client"; const client = new XrplClient( ["ws://localhost:1337", "wss://xrplcluster.com"], { assumeOfflineAfterSeconds: 15, maxConnectionAttempts: 4, connectAttemptTimeoutSeconds: 4, } ); ``` ``` -------------------------------- ### Initialize XrplClient with Custom Options Source: https://github.com/xrpl-labs/xrpl-client/blob/main/README.md Demonstrates how to instantiate the XrplClient with specific connection and reconnection configurations. This includes settings for offline detection, connection attempt limits, and timeouts. ```typescript import { XrplClient } from "xrpl-client"; const client = new XrplClient( ["ws://localhost:1337", "wss://xrplcluster.com"], { assumeOfflineAfterSeconds: 15, maxConnectionAttempts: 4, connectAttemptTimeoutSeconds: 4, } ); ``` -------------------------------- ### Client Methods Source: https://github.com/xrpl-labs/xrpl-client/blob/main/README.md This section details the core methods available on the XrplClient instance for interacting with the XRPL. ```APIDOC ## Client Methods ### Description Provides essential methods for sending commands, managing connection state, and controlling the client lifecycle. ### Methods - **send({ command: "..." }, {SendOptions})** » `Promise` Sends a command to the connected XRPL node. Returns a Promise that resolves with the response or rejects on error. - **ready()** » `Promise` Returns a Promise that resolves when the client is fully connected and has received initial ledger data. - **getState()** » `ConnectionState` Returns the current connection, connectivity, and server state (e.g., fees, reserves). - **close()** » `void` Closes the connection. The client object can be reused after calling `reinstate()`. - **reinstate(options?: {forceNextUplink: boolean})** » `void` Reinstates a closed connection. If `forceNextUplink` is `true`, it attempts to connect to the next available uplink instead of starting from the first. This option is ignored if `tryAllNodes` was set to `true` during initialization. - **destroy()** » `void` Fully closes and destroys the client object. It cannot be reused afterward. ``` -------------------------------- ### Instantiate XRPL WebSocket Client (TypeScript) Source: https://github.com/xrpl-labs/xrpl-client/blob/main/README.md Demonstrates how to create an instance of the XrplClient. By default, it connects to a set of public XRPL nodes and attempts to reconnect indefinitely. Custom endpoints and options can be provided. ```typescript import { XrplClient } from "xrpl-client"; const client = new XrplClient(); // Uses default endpoints: ['wss://xrplcluster.com', 'wss://xrpl.link', 'wss://s2.ripple.com'] // with maxConnectionAttempts option set to null (try forever). ``` -------------------------------- ### Configuring XRPL Client with a Proxy Source: https://github.com/xrpl-labs/xrpl-client/blob/main/README.md Demonstrates how to configure the XRPL client to use a proxy server. This involves creating a proxy-enabled http.Agent (e.g., HttpsProxyAgent) and passing it within the 'httpRequestOptions' during client initialization. ```javascript import { HttpsProxyAgent } from "https-proxy-agent"; const agent = new HttpsProxyAgent({ host: "proxy.corporate.lan", port: 3128, }); const client = new XrplClient("wss://xrplcluster.com", { httpRequestOptions: { agent }, }); ``` -------------------------------- ### Enabling XRPL Client Debugging Information Source: https://github.com/xrpl-labs/xrpl-client/blob/main/README.md Explains how to enable detailed debugging information for the XRPL client during development. This involves compiling the TypeScript code and running the resulting JavaScript file with the 'DEBUG' environment variable set to 'xrplclient*'. ```bash tsc DEBUG=xrplclient* node someFile.js ``` -------------------------------- ### XRPL Client Wrapper for rippled-ws-client Compatibility Source: https://github.com/xrpl-labs/xrpl-client/blob/main/README.md Shows how to create a wrapper class for 'xrpl-client' to maintain compatibility with systems expecting 'rippled-ws-client'. This is useful when integrating with older codebases or libraries that depend on the original client's interface. ```javascript class RippledWsClient extends XrplClient {} // Then use RippledWsClient ``` -------------------------------- ### XRPL Client Connection Events Sequence Source: https://github.com/xrpl-labs/xrpl-client/blob/main/README.md Illustrates the sequence of connection events for the XRPL client, including retries, node switches, and connection status changes. This helps in understanding the client's behavior during network disruptions or node failures. ```text 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 ``` -------------------------------- ### Send Options Source: https://github.com/xrpl-labs/xrpl-client/blob/main/README.md Details the options that can be passed to the `send` method to control request timeouts and behavior during reconnections. ```APIDOC ## Send Options ### Description Customize the behavior of the `send` method with options related to timeouts and subscription replay. ### Options - **timeoutSeconds** (Number) The maximum time (in seconds) to wait for a response before rejecting the Promise. This timeout starts when the command is issued. - **timeoutStartsWhenOnline** (Number) If `true`, the `timeoutSeconds` will only start counting once the connection is marked as online (WebSocket connected and `server_info` received). - **sendIfNotReady** (Boolean) If `true`, commands will be sent once the WebSocket is connected, even if a valid `server_info` response has not yet been received. - **noReplayAfterReconnect** (Boolean) If `false`, subscription commands will be automatically replayed to the new node upon reconnection. Setting to `true` prevents this replay. ``` -------------------------------- ### Emitted Events Source: https://github.com/xrpl-labs/xrpl-client/blob/main/README.md Lists the events that the XrplClient can emit, indicating changes in connection state, messages, and ledger activity. ```APIDOC ## Emitted Events ### Description These events are emitted by the XrplClient to signal various occurrences, such as connection status changes, incoming messages, and XRPL-specific activities. ### Events - **state**: Emitted when the connection state changes (e.g., from online to offline). - **message**: Emitted for all incoming messages, including duplicates. - **ledger**: Emitted when a new ledger closes. - **path**: Emitted for asynchronous `path_find` responses. - **transaction**: Emitted for transaction-related events. - **validation**: Emitted for transaction validation events. - **retry**: Emitted when a new connection attempt is made. - **close**: Emitted when the upstream connection is closed. - **reconnect**: Emitted after a successful reconnection (following a `state` change to online). ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.