Timelock/Locktime

What Is a Timelock/Locktime?

A timelock, also known as locktime, is a feature in cryptocurrencies that allows users to set conditions on when a transaction can be included in the blockchain and considered valid.

It was introduced by Satoshi Nakamoto, the creator of Bitcoin, as a means to control the timing of transactions.

The Power of Timelocks in Blockchain

Timelocks are implemented based on either a specific block height or a timestamp, and they ensure that transactions cannot be confirmed until a certain time or block height has been reached.

This feature provides additional security and control over the execution of transactions.

There are Two Types of Timelocks

  1. Absolute timelocks: These are based on a specific time in the future. Transactions with absolute timelocks can only be included in a block after a predetermined time.
  2. Time-relative timelocks: These are based on a certain amount of time that must elapse before a transaction can be confirmed. Transactions with time-relative timelocks require a specific duration to pass before they can be included in a block.

Time Can be Measured in Two Ways

  1. Using the block number: The timelock specifies a specific block height, and miners must wait until that block is reached before confirming the transaction.
  2. Using the timestamp: The timelock specifies a specific time in Unix timestamp format, and miners must wait until that period has elapsed before confirming the transaction.

Bitcoin has Several Timelock-related Features

  • nLockTime: This is an absolute timelock at the transaction level. It specifies the earliest time or block height at which a transaction can be included in a block.
  • nSequence: This is a time-relative timelock at the transaction level. It determines the time or number of blocks that must pass before a transaction can be confirmed.
  • CheckLockTimeVerify (CLTV): This is an absolute timelock at the script level. It allows a transaction to be spent only after a specified time or block height has been reached.
  • CheckSequenceVerify (CSV): This is a time-relative timelock at the script level. It enables a transaction to be spent only after a certain amount of time or blocks have passed since the input transaction.

Overall, timelocks provide flexibility and control over the timing of cryptocurrency transactions, allowing users to enforce specific conditions before their transactions can be confirmed on the blockchain.