Technical

What is transaction expiration on XRPL?

Last updated:

Transaction expiration on the XRP Ledger allows senders to specify a deadline for transaction inclusion, preventing indefinite pending states and enabling reliable transaction management. This mechanism uses the LastLedgerSequence field to create time-bounded transactions that either validate quickly or become permanently invalid.

The LastLedgerSequence field specifies the maximum ledger index in which a transaction can be included. If a transaction isn't validated by the specified ledger, it becomes permanently invalid and will never be processed. This creates deterministic outcomes - transactions either succeed quickly or fail definitively, eliminating uncertainty.

Without expiration, transactions could theoretically remain pending indefinitely if network conditions prevent validation. While this rarely happens in practice, the possibility creates problems for applications that need certainty. Did the transaction fail, or is it still pending? Should it be retried, risking a duplicate? Expiration resolves these ambiguities.

The ledger sequence number increments with each validated ledger, approximately every 3-5 seconds. Setting LastLedgerSequence to the current ledger number plus 4 gives the transaction roughly 12-20 seconds to validate. This brief window is usually sufficient for normal network conditions while preventing extended pending periods.

Applications commonly set LastLedgerSequence to current_ledger + 4 or current_ledger + 10, balancing quick expiration with tolerance for temporary network delays. Very short expirations (current + 1 or current + 2) risk premature expiration before transactions propagate through the network. Longer expirations reduce expiration risk but extend uncertainty periods.

When a transaction expires without validation, it becomes permanently invalid with no effect on the ledger. The sequence number isn't consumed, the fee isn't charged, and applications can safely retry with a new transaction using the same sequence number. This retry safety is the primary benefit of transaction expiration.

Monitoring transaction status becomes straightforward with expiration. Applications submit transactions with LastLedgerSequence set, then monitor validated ledgers. If the transaction validates before the specified ledger, it succeeded. If the specified ledger passes without the transaction validating, it definitively failed. No ambiguity exists.

Transaction expiration interacts with sequence numbers to provide reliable idempotency. Since expired transactions don't consume sequence numbers, applications can implement simple retry logic: submit transaction with sequence N and LastLedgerSequence L, wait for ledger L, if not validated then retry with the same sequence N but new LastLedgerSequence.

Network congestion can cause unexpected expirations. If validators are processing many transactions and your transaction doesn't make it into a ledger before expiration, it fails even though nothing was technically wrong. In such cases, resubmitting with a higher fee and later LastLedgerSequence usually succeeds.

The relationship between expiration and transaction fees is important. Expired transactions don't charge fees, so aggressive expiration doesn't cost extra XRP. However, repeatedly submitting transactions that expire due to too-short expiration windows wastes network resources and should be avoided.

Transaction expiration differs from timeout in traditional payment systems. A timeout is when a response doesn't arrive within expected time, creating uncertainty. Expiration is definitive - the transaction provably did not and will not process. This certainty enables reliable state management in distributed applications.

Developers building payment applications should always include LastLedgerSequence in transactions unless they have specific reasons for unlimited validity. The rare cases where indefinite validity is desirable involve transactions that must eventually process regardless of delay, though such scenarios are uncommon.

Automatic resubmission logic improves user experience. When a transaction expires, applications can automatically resubmit it with updated LastLedgerSequence rather than requiring user intervention. This creates apparent reliability even if initial submission encounters network issues.

Expiration monitoring must account for ledger timing variations. While ledgers usually close every 3-5 seconds, occasional delays occur. Applications should monitor actual validated ledger sequences rather than relying on time-based assumptions about when specific ledger numbers will validate.

Some wallet software doesn't prominently expose LastLedgerSequence configuration, using default values instead. Understanding these defaults helps users anticipate transaction behavior. Well-designed wallets set appropriate expirations automatically while allowing advanced users to customize when needed.

The combination of transaction expiration, sequence numbers, and deterministic validation creates reliable transaction semantics on XRPL. Applications can submit transactions knowing they'll receive definitive outcomes quickly, enabling robust state management and user experiences comparable to centralized systems.

Was this helpful?

Related Questions

Go Deeper

Expand your knowledge with these related lessons

Transaction Security Model

60 minadvanced

XRPL Transaction Lifecycle Analysis - Where Time Goes

55 minadvanced

Ledger Close and Finality

Finality verification library for XRPL applications with proof generation

37 minintermediate

Have more questions?

Browse our complete FAQ or contact support.