How To Create Time-locked Transactions with Bitcoin (Free Bitcoins Inside!)

in #bitcoin6 years ago

In this guide I will be explaining how to easily create a time-locked transaction on the Bitcoin blockchain. Time-locked transactions could be seen as a form of primitive smart contracts that allow you to create transactions that cannot be spent before a certain date or block height.

We will be using a local copy of the Coinb.in website, which you can download through Github. I strongly recommend you to make sure your computer is free from malware before you continue.



As an added bonus for reading this guide, I will be creating a time-locked transaction (worth 0.0014 BTC) that you can claim once the lock expires.

Before We Start


It’s recommended that you create a new Bitcoin address, we will be using the public and private keys of this address to create and unlock our time-locked transaction.

I’ve used Electrum to generate a new address, I assume that this process is easy enough that it doesn’t require any further explanation.

You can see that I’ve funded this newly generated address with 0.0015 BTC. You can claim this amount after the timelock expires (minus fees). This way I also don’t have to worry about showing you the private keys and it gives you hands on experience with claiming a time-locked Bitcoin transaction.


Newly Created Bitcoin Address:


1. Creating time-locked address & sending your coins


Download a local copy of Coinbin


Go to Coinb.in and download the master branch of their website through Github. I’m not going to link the actual download here, because it’s very important that you know you’re downloading from a trusted source.

Extract the archive and open the index.html file in your browser of choice. You’re now running a local copy of the coinb.in website.


Download Coinbin Master Branch:


Extract the archive and open Index.html:


Now we're working with a local copy of the Coinb.in website, check the address bar to be sure.

Address Time-Lock


Make sure that you're using a local copy of the Coinbin website (as shown above) and create your time-locked address. Click on: 'New' >> 'Time Locked Address' in the top menu.

Fill in the public key of the address you've created with Electrum and enter either a date or block height by which the transaction should be unlocked.


Where to find your public key:

Public key:

Enter your public key and set date or block height on Coinbin:


 
These coins can't be spend before 02/23/2018 15:00


Submit


Make sure you've filled everything in correctly and press the 'Submit' button.

Now you'll see a newly generated address to which you can send Bitcoin. Any coins you send to this address can only be redeemed after a certain date or block height has been reached.

You will also see a redeem script, you should save this or otherwise you won't be able to redeem your coins afterwards.

Redeem script: 04601e905ab175210299f20c7c1580c273c7f3a92100e7cfb37c4c249c0af1e25473f279882feeb0bfac


Payment address & redeem script


Sending the transaction:


That's it! You've now successfully locked your Bitcoins, they can't be spend before 02/23/2018 - 15:00. If you want to claim the coins I've used in this example, be sure to read the next section.


2. Redeeming your coins


Create a new transaction


Again, only use your local Coinb.in copy.

Go to 'New' >> 'Transaction'

Paste your redeem script and click on 'Load'.


After pressing 'Load':


Enter the address you want the coins to be transferred to in the 'Address' field. Use another address than the one you've used to create this time-locked transaction.

Fill in the amount of Bitcoins you want to send. Use only part of the balance, the rest will be used for fees. In this case, you can fill in 0.0013 BTC, so 0.0001 BTC will be used as a fee.

Click 'Submit' after reviewing everything you've put in.


Now you should copy the raw transaction output as seen below.


Raw transaction output:


Output: 010000000166da16875ef2a243ab76c2b94d40964a24d4cd0b87546943d529183d1e20c24d000000002a04601e905ab175210299f20c7c1580c273c7f3a92100e7cfb37c4c249c0af1e25473f279882feeb0bfac0000000001d0fb0100000000001976a9148129c607ca292d6169b139fc183ad565c0b66ea888ac601e905a


After you've copied the raw transaction output, you should click on the 'Sign' tab and fill in the private key of the address used to create the time-locked transaction together with the raw transaction output. This is why we created a completely new address, you should never input your private keys unless you will not be using that address again.



Private key: KzCJXib6ba6kUT5oCDu98GtUGULSYNEuPeTmozMUq22BQoDbWZnC


Now you'll receive a signed transaction hash that you can broadcast to receive your time-locked Bitcoins.



Finally, go to the 'Broadcast' tab to paste the signed transaction. The coins will only be sent if the date or block height of the time-locked transaction has expired.



You'll get an error like this when you try to broadcast before the time-lock expires:


Grab your coins!

Within this message I've made it possible for you to claim my time-lock worth 0.0014 BTC (minus fees). All you need to do is enter the redeem script and private keys, which I've shown in this post.


TL;DR


To create the Time Locked Address:

Go to Coinb.in;
Click on 'New' >> 'Time Locked Address'
Enter your public key (Of the address you created with Electrum)
Enter date + time or block height of when you want your Bitcoins released
Submit
Save the Redeem Script
Send the bitcoins you want to keep locked to the Address generated.


Spend your coins after the time-lock expires.

Go to Coinb.in
Click on: 'New' -> 'Transaction'

Paste your Redeem Script and click Load (it shows every input available to be spent)
Paste the address you want to send the coins to at the "Address" field and the amount in the "Amount" field. The remaining funds will be used as fee. E.g: If your address has 0.015BTC, you can put 0.0014BTC in the
"Amount" field and the fee will be 0.0001BTC (Making 0.0015 in total)
Press 'Submit' and copy the raw transaction

Click on the "Sign" tab
Paste the private key from the Electrum address you created
Paste the raw transaction (you've gotten this from the 'transaction' page.)
Press 'Submit'. Now you've received a 'signed transaction' script

Click on the 'Broadcast' tab and paste the signed transaction script

Transaction is sent! Or not, if you've made an error or if you try to do this before the time-lock has expired.

TL;DR: courtesy of Bitcointalk user Tryninja


Sources

 
This tutorial is a more in-depth version of Tryninja's time-lock explanation on Bitcointalk.

All images are screenshots taken by me.

Coinb.in

The Bitcoin Wiki on Time-locked transactions

Sort:  

Will look in to this. Did not realize this was possible. Blockchain tech never stops to amaze me!

Not that hard to understand. Follow the guide to claim the 0.0014 BTC ;)

Congratulations, you were selected for a random upvote! Follow @resteemy and upvote this post to increase your chance of being upvoted again!
Read more about @resteemy here.

Coin Marketplace

STEEM 0.20
TRX 0.12
JST 0.028
BTC 64400.67
ETH 3506.16
USDT 1.00
SBD 2.53