xrpl-txdata
: Fetch XRPL transaction data (auto failover)
This lib. allows you to fetch XRP ledger transaction outcome from a number of (full history) XRP ledger nodes. This lib. will automatically setup connections when fetching from a selected node takes too long. The first (sane) reply will be returned.
This lib. will get you the fastest response possible while setting up a minimal amount of websocket connetions to full history XRPL nodes.
This package can be used in Node/Typescript projects (xrpl-txdata
) or used (browserified) in the browser.
Not only the requested transaction will be returned (or the not found
response if the transaction can't be found): the parsed balances (transaction outcome) will be calculated (form the transaction metadata) and returned as well.
A simple ES6 JS example can be found in samples/dev.js
.
Syntax
Basic usage: construct (using defaults), fetch one transaction and close WebSocket connection(s) after getting a result.
const txd = const main = async { // getOne(): fetch one tx and close connection(s) after a reply const tx = await txd console}
Fetching multiple transactionos and close the WebSocket connection(s) programmatically:
const txd = const main = async { // get(): fetch a tx, keep connetion(s) alive const tx1 = await txd console const tx2 = await txd console // Done, not interested in more tx data, close connection(s) txd}
Advanced options
By default, these full history nodes will be used (in order):
wss://xrpl.ws
(more info)wss://xrpl.link
(fallback endpoint forwss://xrpl.ws
)wss://s2.ripple.com
The default timeout configuration will:
- Try to connect, query & get a response (per tx) within 1250ms (1.25 seconds) before trying the next node
- Try to connect, query & get a response (per tx) within 10 seconds
The first node to anwer the request will result in a resolved query.
To overrule the nodes (full history required), provide an array with websocket endpoints to the constructor in the order you'd like them to be used:
const txd = 'wss://my-fh-xprl-node.local' 'wss://s2.ripple.com' 'wss://xrpl.ws'
To overrule the default 1250 / 10000 ms timeouts, provide an object to the constructor (second param.):
// Empty array (endpoints) will result in using the default server listconst txd = // Try the next server after 0.75 sec. EndpointTimeoutMs: 750 // Throw an error if none of the servers connected & replied in 5 seconds OverallTimeoutMs: 5000
Use in the browser
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.
Response (format)
The response of a .get(someTxHash)
/ .getOne(someTxHash)
call contains four properties:
host
(string): the endpoint (connetion url) of the first node replying to the requestresolvedBy
(string):"generator"
if the host replied within theEndpointTimeoutMs
timeout,"emitter"
if the first reply came in after theEndpointTimeoutMs
timeout, but before the next host repliedresult
(object): containing the error or transaction response from the XRPL nodebalanceChanges
(object): containing the parsed balance changes for all accounts affected by this transaction
Sample: response for a non existing transaction:
Sample: response for an existing transaction (simple payment):
Sample: response for an existing transaction (Decentralized Exchange trade):