@xyrawallet/tx-parser
v1.1.1
Published
Human-readable transaction parser for XRPL and Xahau
Downloads
279
Maintainers
Readme
@xyrawallet/tx-parser
Human-readable transaction parser for XRPL and Xahau. Converts raw transaction JSON into structured, display-ready objects with titles, descriptions, labeled fields, and warnings. Zero runtime dependencies — pure TypeScript.
Installation
npm install @xyrawallet/tx-parserBasic Usage
import { parseTransaction } from '@xyrawallet/tx-parser';
const tx = {
TransactionType: 'Payment',
Account: 'rN7n3473SaZBCG4dFL83w7p1W9cgZw6w3T',
Destination: 'rfkE1aSy9G8Upk4JssnwBxhEv5p4mn2KTy',
Amount: '5000000',
Fee: '12',
};
const result = parseTransaction(tx);
// result.title → "Payment"
// result.description → "Send 5 XRP (5,000,000 drops) to rfkE1aSy..."
// result.fields → [{label, value, displayValue, type}, ...]
// result.network → "xrpl"Specifying the Network
By default the parser infers the network from the transaction type. For standard XRPL transaction types executed on Xahau (where the native currency is XAH, not XRP), pass the network option explicitly:
import { parseTransaction, ParseOptions } from '@xyrawallet/tx-parser';
const result = parseTransaction(tx, { network: 'xahau' });
// result.description → "Send 5 XAH (5,000,000 drops) to rfkE1aSy..."
// result.network → "xahau"The displayValue Pattern
Every ParsedField includes a displayValue string — always a flat, human-readable string, even for nested fields. Simple consumers can render a flat list using only displayValue:
result.fields.forEach(field => {
console.log(`${field.label}: ${field.displayValue}`);
});Structured Value for Rich UIs
For rich UIs, use field.value which can be either a string or a nested ParsedField[] (for array/object types). This enables recursive rendering of complex fields like Memos, Hooks, and Signer Lists.
Exported Helpers
These standalone helpers are available for consumers who need them independently:
decodeCurrencyCode(currency)— Decode 40-char hex currency codes (e.g., RLUSD)formatAmount(amount, nativeCurrency?)— Format drops or IOU amountsformatAsset(asset)— Format asset specifiers (no value, just currency/issuer)shortenAddress(address)— Truncate long addresses for displayrippleTimeToDate(rippleTime)— Convert Ripple epoch to JS DatedecodeMemoData(hex)— Decode hex-encoded memo datadecodeFlagBitmask(flags, flagMap)— Decode transaction flag bitmasks
Supported Networks
- XRPL: Payment, TrustSet, OfferCreate, OfferCancel, AccountSet, AccountDelete, DepositPreauth, SignerListSet, EscrowCreate/Finish/Cancel, PaymentChannelCreate/Claim/Fund, CheckCreate/Cash/Cancel, NFTokenMint/Burn/CreateOffer/CancelOffer/AcceptOffer, AMMCreate/Deposit/Withdraw/Vote/Bid/Delete, Clawback
- Xahau: Import, Invoke, ClaimReward, GenesisMint, URITokenMint/Burn/Buy/CreateSellOffer/CancelSellOffer, Remit, SetHook, EmitFailure
All standard XRPL transaction types are also supported on Xahau when { network: 'xahau' } is provided — native amounts will display as XAH instead of XRP.
Unknown transaction types return a graceful fallback with raw field display rather than throwing an error.
