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.
You can use locktime to make sure that a transaction is locked until a specific block height, or a point in time.
||Unlocked at block height.|
||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.
Most transactions do not make use of locktime, so their locktime is set to
||This transaction could only be relayed on the network after the blockchain reached a height of 452,845. (tx)|
||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)|
||This is Tue, 08 Jul 1997 14:54:41 in Unix Time. This is effectively like setting the locktime to
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,499 years before we hit block 500,000,000.
- The current unix time is
1,624,550,541(also known as 24 June 2021, 17:02:21), which is already above