Loading Tool

Locktime

Post-dating a bitcoin transaction

Diagram showing how the locktime field can be used to prevent a transaction from being mined until a specific block height or time in the future.

The locktime field allows you to prevent a transaction from being mined until after a specific block height or time.

A transaction with a locktime in the future will not be accepted or relayed by nodes either, so you have to store it locally until the locktime you have set on the transaction has passed.

In other words, setting a locktime on a transaction is the equivalent of post-dating a cheque.

An image of a post-dated cheque representing a transaction with a locktime of a specific block height.

Usage

How does locktime work?

The locktime field is 4 bytes in size and can hold values between 0 (0x00000000) and 4294967295 (0xffffffff).

You can set a specific block height or time by using different ranges of values:

Locktime Description
<=499999999 Transaction cannot be mined until after a specific height.
>=500000000 Transaction cannot be mined until after a specific time.

This is also known as "absolute locktime", as you're setting a specific height or time in the future. It's also possible to set a relative locktime on a transaction if you prefer.

For the locktime field to be enabled, at least one of the sequence values on the inputs must be set to 0xfffffffe or below. If all of the inputs' sequence values are set to the maximum value of 0xffffffff, the transaction is considered "final" and the locktime feature is disabled.

Height

0 to 499999999

Diagram showing the locktime field being used to set a specific block height.

By setting the locktime between 0 (0x00000000) and 499999999 (0x1dcd64ff) you can specify that the transaction can only be mined into the blockchain after a specific height.

This is a more than suitable range, as the blockchain is not expected to reach a height of 499,999,999 for another .

Time

500000000 to 4294967295

Diagram showing the locktime field being used to set a specific block time.

By setting the locktime between 500000000 (0x1dcd6500) and the maximum value of 4294967295 (0xffffffff) you can specify that the transaction can only be mined into the blockchain after a specific time.

This time value is in Unix Time:

tool-6a47173690234