Input Sequence (nSequence)

2 min read

An input sequence, or nSequence, is a field of a Bitcoin transaction input. The sequence of an input was originally intended to enable payment channels similar to the Lightning Network. This design was implemented in the first version of Bitcoin, but such on-chain payment channels were quickly found to be insecure, so the functionality was disabled, leaving the sequence field unused for several years.

With the adoption of BIP 125, the sequence field came into use once again. Currently, input sequences are used to signal support for Replace-by-Fee (RBF), which allow a user to replace an unconfirmed transaction and with a similar transaction that pays a higher fee.

If a user broadcasts a transaction with a low fee, and the transaction is not being confirmed in the desired time, RBF allows the user to increase the fee, incentivizing miners to confirm the transaction faster.

Learn more about Replace-by-Fee (RBF).

Originally, the input sequence was meant to allow transactions to be replaced dynamically, allowing Bitcoin payment channels to be created on-chain. On-chain channels would have worked as follows.

Alice and Bob create a transaction with some inputs and outputs, and set the input sequences to zero and the locktime to some point in the future, preventing the transaction from being included in a block until that point. In the meantime, Alice and Bob can pay each other back and forth by changing the amounts in the outputs and incrementing the sequence, which acts like a version counter for the transaction itself. If, at any point, Bob and Alice want to finalize their payment channel, they can set the sequence to its maximum value, precluding any further updates. When the locktime is reached, a miner will include the most up-to-date version of the transaction in a block, finalizing it.