5

Is it possible to submit some coins to some address and make them spendable after some period of time?

Like I want submit 1btc to address 1Kc24m... and make that output to be spendable after january 1st 2030.

1 Answer 1

5

Yes, you can use OP_CHECKLOCKTIMEVERIFY opcode in the locking script of the output. This opcode takes either blocks or Unix Epoch Time (seconds since 1-Jan-1970) as the parameter to lock. If the parameter is non-zero and below 500 million, it is interpreted as a block height, if it is greater than or equal to 500 million, it is interpreted as a Unix Epoch timestamp. When you would reference this UTXO at the time of spending, you need to set the transaction nLocktime equal to or great than the OP_CHECKLOCKTIMEVERIFY. The nLocktime parameter while spending should be same as what was specified in the CLTV; i.e. if the CLTV locking parameter was in blocks, it should be specified in blocks, otherwise in Unix Epoch timestamp.

Since you want it to be spendable after 1st Jan 2030, that is equivalent to timestamp of 1,893,456,000 (or 0x70dbd880). So your locking script will be concatenation of:

OP_DATA (size of CLTV_expiry): 0x04
CLTV (little endian): 0x80d8db70
OP_CLTV: 0xb1
OP_DROP: 0x75
OP_DUP: 0x76
OP_HASH160: 0xa9
OP_DATA (size of address): 0x14
Address: <address>
OP_EQUALVERIFY: 0x88
OP_CHECKSIG: 0xac

Two things to note: (1) When you are spending this transaction, the input referencing this UTXO needs to have nSequence value between 0xF0000000 to 0xFFFFFFFE. (2) Median_time (time of last 11 blocks) is used to check nLocktime when the script is evaluated which is generally about hour behind the actual time on your wall clock.

3
  • How can one build such a transaction, though, except with a binary/hex editor, "manually"?
    – Gabriel
    Feb 19, 2021 at 19:51
  • @Gabriel you can try this link which has multiple examples and code samples bcoin.io/guides/cltv.html
    – pseudozach
    May 10, 2021 at 22:46
  • Can the nSequence field be any value as long as it's not 0xffffffff?
    – greatwolf
    Dec 21, 2022 at 2:06

Your Answer

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

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