Timelock
Also called: time lock, time-lock, locktime, nLockTime, absolute timelock, relative timelock.
A timelock is a rule that stops bitcoin from being spent until a set block height or time, or until the coin has aged a set amount since it confirmed.
A timelock prevents a transaction or an output from being spent before a certain point. Bitcoin has two kinds, each available as a transaction field and as a Script opcode:
| Absolute ("not before X") | Relative ("not until N after confirmation") | |
|---|---|---|
| Transaction field | nLockTime | nSequence (BIP 68) |
| Script opcode | OP_CHECKLOCKTIMEVERIFY (BIP 65) | OP_CHECKSEQUENCEVERIFY (BIP 112) |
| Measured in | Block height or Unix time | Blocks or units of 512 seconds |
| Enforced since | Field: 2009; opcode: block 388,381 | Block 419,328 (July 2016) |
How timelocks work
The transaction fields say when the transaction itself may be mined. nLockTime values below 500,000,000 are block heights and larger values are Unix timestamps. The opcodes go further: they put the condition in the locking script, so the coins can't move until the time has passed, whoever signs. Time-based locks are measured against median time past, the median of the last 11 block timestamps (BIP 113), so miners can't game them by misreporting the time.
What timelocks are used for
- Lightning channels and HTLCs, which need refund and penalty deadlines.
- Vaults and inheritance plans, where a backup key only works after a delay.
- Escrow that times out, and timelocked fidelity bonds (BIP 46).
- Anti-fee-sniping: many wallets set nLockTime to the current block height.
Compare the two opcodes in BIP 65 vs BIP 112.