Spending a time-locked bitcoin transaction

Thomas McCabe
2 min readSep 29, 2016

--

How time flies! Last week, I detailed how to build a bitcoin transaction that was unspendable until a specific point in the future. We utilized OP_CHECKLOCKTIMEVERIFY to lock bitcoins (on testnet) for one week, and today, we can spend them!

Success! The previous post detailed how to build a transaction so I won’t describe step-by-step instructions to construct the spending transaction.

Here’s a link to our new transaction, and the signed transaction in hex format:

0100000001726f90610c79af5f237326855d63355c99628593da6ba96dc0942b256af0aa12000000008b47304402205b1f7ae4145526f33128d92aa74e3b8f6c7369e063506658c4a17119ce9526e00220015df72bed40c5ead4bcd7b732aa36627a8baa6d6b7d38e9de34b9fdb27eac56012102f0141fadbe6757ed04b7a25dad0c78af8b97af09744318cf15c66a4566fa2ec920042d25ec57b17576a914225d81ac31f9c8368033e1d380b8be1860d53c5d88ac0000000001007a3f00000000001976a9146b3a858370ea6ed841633611fcfdeae7bf85f86288ac9125ec57

And decoded for readability:

{
"txid": "ca2c7347aa2fdff68052f026fa9a092448c2451f774ca53f3a2b05d74405addc",
"size": 224,
"version": 1,
"locktime": 1475093905,
"vin": [
{
"txid": "12aaf06a252b94c06da96bda938562995c35635d852673235faf790c61906f72",
"vout": 0,
"scriptSig": {
"asm": "304402205b1f7ae4145526f33128d92aa74e3b8f6c7369e063506658c4a17119ce9526e00220015df72bed40c5ead4bcd7b732aa36627a8baa6d6b7d38e9de34b9fdb27eac56[ALL] 02f0141fadbe6757ed04b7a25dad0c78af8b97af09744318cf15c66a4566fa2ec9 042d25ec57b17576a914225d81ac31f9c8368033e1d380b8be1860d53c5d88ac",
"hex": "47304402205b1f7ae4145526f33128d92aa74e3b8f6c7369e063506658c4a17119ce9526e00220015df72bed40c5ead4bcd7b732aa36627a8baa6d6b7d38e9de34b9fdb27eac56012102f0141fadbe6757ed04b7a25dad0c78af8b97af09744318cf15c66a4566fa2ec920042d25ec57b17576a914225d81ac31f9c8368033e1d380b8be1860d53c5d88ac"
},
"sequence": 0
}
],
"vout": [
{
"value": 0.0416,
"n": 0,
"scriptPubKey": {
"asm": "OP_DUP OP_HASH160 6b3a858370ea6ed841633611fcfdeae7bf85f862 OP_EQUALVERIFY OP_CHECKSIG",
"hex": "76a9146b3a858370ea6ed841633611fcfdeae7bf85f86288ac",
"reqSigs": 1,
"type": "pubkeyhash",
"addresses": [
"mqHvhj9hzjzQ2SbcRrxU2aV8zsWkmK6gbh"
]
}
}
]
}

A few things to note here. In our input, we have the txId of the transaction we created last week, and the index of the input from that tx — we are directly referencing our previous transaction to justify how we are funding this new transaction. The scriptSig contains 3 components: (i) our ECDigitalSignature proving we had the private key needed to spend the previous output, (ii) the redeemScript that was hashed to make the P2SHScriptPubKey, and (iii) the public key associated with that redeemScript. You can verify these data sets in last week’s post.

Here’s our redeemScript we needed to satisfy in order to fund this new transaction:

1475093805 OP_CHECKLOCKTIMEVERIFY OP_DROP OP_DUP OP_HASH160 225d81ac31f9c8368033e1d380b8be1860d53c5d OP_EQUALVERIFY OP_CHECKSIG

Notice our new transaction’s lockTime value is 1475093905, meaning this transaction is not able to mined until Wed, 28 Sep 2016 20:18:25 GMT. In our previous transaction, we created an output to be locked until 1475093805 — our CLTV value. Our new transaction’s locktime is greater than the CLTV value — one of the conditions needed for OP_CLTV to NOT fail.

Bitcoin’s scripting language is very powerful, but access to resources with regards to learning how to build a script is scarce. We hope Bitcoin-S can help solve this problem.

If you enjoyed reading, please follow us on GitHub/Twitter:

GitHub: https://github.com/bitcoin-s/bitcoin-s-core

Twitter: https://twitter.com/TomMcCabeBTC

https://twitter.com/SuredBits

--

--