I am trying to create a timelock transaction, but I am unable to use a UNIX timestamp on testnet. However, if I use a block height the transaction works.

When I use a block height that is in the future and broadcast the transaction, I get:

sendrawtransaction RPC error: {"code":-26,"message":"non-final"}

When the block height is reached, the transaction goes through as expected.

When I make the locktime above 500,000,000 I get a different message:

"non-mandatory-script-verify-flag (Locktime requirement not satisfied)"

I have tried several different random timestamps from various years (2013, 2020) and I get the same error message. If I make the transaction with a large locktime like 400,000,000 I get the expected "non-final" message. It only happens when I go over the 500,000,000 minimum.

I have decoded both transactions, and the only noticable difference is the locktime.

Here is the raw transaction with the UNIX timestamp from 2013:


Here is the raw transaction with block height:


1 Answer 1


The input to your transaction has a script that uses OP_CHECKLOCKTIMEVERIFY. This opcode takes the item at the top of the stack and compares its value to the locktime given in the transaction. However, because the locktime can be either a height or a timestamp, it also checks that the comparison is comparing two heights or two timestamps, not both. So it applies the same height and timestamp mode switching rules.

If you we look at the redeemScript in more detail, we find that it pushes a 0 before the OP_CHECKLOCKTIMEVERIFY, so 0 is the locktime to compare against. Since 0 is less than 500,000,000, this value is interpreted as a height locktime of 0. However your transactions locktime is greater than the threshold, so it is interpreted as a timestamp. Since height and timestamp cannot be compared, the script interpreter throws an error here and causes the transaction to be invalid. Thus the only way to use this script is to use exclusively height based locktimes.

  • Thank you so much! I’ve been hacking at this for days. I found the problem in my code.
    – Cannabijoy
    Nov 7, 2022 at 18:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.