Transaction lock time

nLockTime

A transaction no block may include until a chosen block height or time has passed.

What it is

Every transaction ends with a lock time field, and most leave it at 0. A nonzero lock time below 500,000,000 is a block height; from 500,000,000 on it is a unix time. The lock binds only when at least one input's sequence number is below 0xffffffff. When every input is final, the rules ignore the lock time. Many wallets set a binding lock time just below the current height on every payment, to discourage miners from rewriting recent blocks (anti-fee-sniping); the next block already meets it, so nobody waits on it. So Bitblocks types a transaction nlocktime only when its lock binds and sits more than 2,016 blocks (or 14 days, two weeks) before the block it was mined in. This lock belongs to the whole transaction, not to one output: it says when the transaction itself becomes valid.

Script pattern

  1. <inputs> At least one input with a sequence below 0xffffffff.
  2. <outputs> Any outputs.
  3. <lock time> 4 bytes: a block height below 500,000,000, else a unix time.

A nonzero lock time with every sequence at 0xffffffff is ignored, and is not this type.

How it is spent

Its outputs are spent as their own scripts say; the lock only decides when the transaction can be mined.

Background

Lock time is in the first Bitcoin release, as the way to replace a transaction before it is final. From 2015, Bitcoin Core set it to the current height with a sequence of 0xfffffffe on every payment, so many transactions from those years carry one; the transaction page shows it, labelled anti-fee-sniping, and these are not this type.

On chain

Examples coming. They come from the blocks we have typed, and no typed block holds one yet.

Specification