Understanding Reliable Transaction Submission
Financial institutions and service providers utilizing the XRP Ledger should follow these best practices to ensure transactions are verified or rejected quickly and verifiably. Always submit transactions to a trusted (locally operated) rippled server.
This guide outlines methodologies to achieve:
- Idempotency – Transactions are processed either once or not at all.
- Verifiability – Applications can definitively determine a transaction’s final outcome.
Risks of Ignoring Best Practices
- Submitting unexecuted transactions erroneously.
- Misinterpreting temporary results as final outcomes.
- Failing to locate authoritative results for previously applied transactions.
Such errors could lead to severe issues (e.g., duplicate payments).
Background
The XRP Ledger protocol maintains a shared ledger across a decentralized network. Transactions are applied via a consensus and validation process:
- Well-formed transactions are typically verified/rejected within seconds.
Exceptions occur if:
- The global transaction cost increases post-submission.
- Transactions lack an expiry (
LastLedgerSequence), allowing indefinite delays.
Power/network outages further complicate status checks.
Transaction Lifecycle
Phases:
- Creation & Signing: An account owner drafts and signs a transaction.
Submission: The transaction is broadcasted to the network.
- Malformed transactions are rejected immediately.
- Valid transactions may temporarily succeed/fail before finalizing.
- Consensus & Validation: Transactions are irreversibly applied to the ledger.
Key Note: A successful submission response only confirms receipt by a rippled server—not ledger inclusion.
Critical Parameters
LastLedgerSequence
- Purpose: Specifies the latest ledger index for transaction validation.
- Best Practice: Set to
(LastValidatedLedgerIndex + 4)for predictability. - Example: If the last validated ledger is
10266396, use10266400.
Warning: Omitting this risks indefinite pending status.
Best Practices
1. Submission Workflow
- Persist Details: Save transaction hashes,
LastLedgerSequence, sender address/sequence, and application-specific data before submission. - Submit: Broadcast the transaction via trusted APIs (
rippled/RippleAPI).
2. Validation Workflow
Check Status: Query by hash using the
txmethod.- Final results include
"validated": true.
- Final results include
- Handle Gaps: If servers lack ledger history, manually fetch missing data or query Ripple’s full-history servers (e.g.,
s2.ripple.com).
Pseudocode for Validation:
for transaction in persisted_transactions:
if result.validated:
finalize_result()
elif LastLedgerSequence > newest_ledger:
wait()
else:
transaction_failed()Technical Implementation
Key Steps:
- Fetch Account Sequence: Use
account_info. - Calculate
LastLedgerSequence: Derived from the last validated ledger. - Build/Sign Transaction: Via
signmethod. - Submit: Use
submit. - Verify: Poll with
txuntilvalidated: true.
Handling Failures
Common Scenarios:
Transaction Included but Failed:
- Cause: Insufficient liquidity, incorrect path.
- Action: Modify and resubmit with updated parameters.
Transaction Not Included:
- Cause: Low fee, network instability.
- Action: Resubmit with a higher fee/new
LastLedgerSequence.
Pro Tip: Use AccountSet with no options to cancel stuck transactions.
FAQ
Q: How do I verify a transaction’s finality?
A: Look for "validated": true in the tx method response.
Q: What if my server lacks ledger history?
A: Use ledger_request or trusted full-history servers.
Q: Can I cancel a pending transaction?
A: Yes—submit a no-op AccountSet transaction with the same Sequence number.