Spending a time-locked bitcoin transaction
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:
And decoded for readability:
"asm": "304402205b1f7ae4145526f33128d92aa74e3b8f6c7369e063506658c4a17119ce9526e00220015df72bed40c5ead4bcd7b732aa36627a8baa6d6b7d38e9de34b9fdb27eac56[ALL] 02f0141fadbe6757ed04b7a25dad0c78af8b97af09744318cf15c66a4566fa2ec9 042d25ec57b17576a914225d81ac31f9c8368033e1d380b8be1860d53c5d88ac",
"asm": "OP_DUP OP_HASH160 6b3a858370ea6ed841633611fcfdeae7bf85f862 OP_EQUALVERIFY OP_CHECKSIG",
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: