Locktime
Field in a transaction used for post-dating.
Locktime sets the earliest time a transaction can be mined in to a block.
It’s the last field in a piece of transaction data.
Usage
You can use locktime to make sure that a transaction is locked until a specific block height, or a point in time.
Locktime | Description |
---|---|
< 500000000 |
Unlocked at block height. |
>= 500000000 |
Unlocked at specific time (in Unix time) |
If you do not want your transaction to be locked until a specific block or time, set the locktime field to 0x00000000
(or anything below the current block height or unix time).
Nodes validate every transaction (and block) they receive. So if they receive a transaction (or a block containing a transaction) with a locktime in the future, they will reject it.
Examples
Most transactions do not make use of locktime, so their locktime is set to 0x00000000
.
Nonetheless:
Locktime | Decimal | Description |
---|---|---|
0xede80600 |
452845 |
This transaction could only be relayed on the network after the blockchain reached a height of 452,845. (tx) |
0x06241559 |
1494557702 |
This is Fri, 12 May 2017 02:55:02 in Unix Time. The transaction could only be relayed on the network after the median time of the last 11 blocks (according to the time field in their block headers) is greater than this. (tx) |
0xb154c233 |
868373681 |
This is Tue, 08 Jul 1997 14:54:41 in Unix Time. This is effectively like setting the locktime to 0x00000000 , as the first ever block was mined on 02 Feb 2011 23:16:42. (tx) |
Notes
In order for the locktime to be effective, you need to set one of the sequence
values (for one of the inputs in the transaction data) to anything below the default maximum (0xffffffff
).
Unix Time is the number of seconds since 1st January 1970.
As mentioned, the locktime has a dual-purpose for setting either a block height or time. This works because:
- It’s going to take 9,498 years before we hit block 500,000,000.
- The current unix time is
1,679,399,062
(also known as 21 March 2023, 11:44:22), which is already above500,000,000
.
Resources
- https://bitcoin.org/en/developer-guide#locktime-and-sequence-number
- http://bitcoin.stackexchange.com/questions/5914/how-is-locktime-enforced-in-the-standard-client
- http://bitcoin.stackexchange.com/questions/2025/what-is-txins-sequence
Source Code
nLockTime
validation.cpp
(IsFinalTx)