Timelock/Locktime is a restriction mechanism built into cryptocurrency transactions. This mechanism defines a specific time or block height for a transaction to be confirmed on the blockchain network. You can think of it as a function of scheduling transactions.
Timelock is a smart contract model that completely or partially blocks miners from confirming a particular transaction. This blocking continues until certain conditions are met. There are two types of timelock: absolute timelock and relative timelock.
Absolute timelock means that a transaction can only be confirmed when a certain time or block height is reached. For example, a transaction can be confirmed on January 1, 2024, or at block 1000000.
Relative timelock means that a transaction can only be confirmed after a certain time frame or number of blocks has passed. For example, a transaction can be confirmed after 10 hours or 100 blocks.
Timelock was added to Bitcoin by Satoshi Nakamoto, the inventor of Bitcoin. Every Bitcoin transaction has at least one timelock field. However, this field is not generally used.
Timelock can express time in the Bitcoin network in two ways: Block number and block timestamp. When a timelock is set based on the block number, miners receive a specific block number and do not confirm the transaction until they reach that block. Once a timelock is set based on a timestamp, miners will not confirm the transaction until a certain amount of time has passed. This time is measured as Unix time.
There are four ways to set a timelock in Bitcoin: nSequence, nLocktime, CheckLockTimeVerify and CheckSquenceVerify. Two of them are at the process level and two at the script level.
nLocktime provides an absolute timelock at the transaction level. nSequence provides a process-level relative timelock. CheckLockTimeVerify provides an absolute script-level timelock. CheckSquenceVerify provides a script-level relative timelock.
Timelock is an important feature that makes cryptocurrency transactions more flexible and secure. Thanks to Timelock, users can perform their transactions at any time or under conditions.