After the transaction has been included into a block, you'll only be able to spend that new output (to the new address) after the locktime is over.
This sounds good. I'm exactly looking for this. I thought the tx itself will be locked. If the fund sent to the address can't be spent, then that’s what I'm looking for. I actually misread above posts and mixed it with something I mentioned (the tx lock). Thanks a lot. No merit to spend.
But unfortunately, that's not how it works... if you specify "nLockTime" in a transaction, it means that the transaction is not able to be included in a block until AFTER that time period has passed. It's like "post dating" a cheque... it can't be cashed until at least the date printed on the cheque.
If you set the locktime for a transaction to be in 100 days, no miner will be able to include that transaction in a block for 100 days... and a lot of nodes won't even propagate the transaction as they will not consider it "final"... this is the error code I get when trying to broadcast a transaction before the LockTime:
non-final (code -26)
Even if you have a transaction that is locked, you could quite easily just create another transaction that spends those same funds, that has no locktime and can be broadcast/confirmed immediately.
To prevent spending, the OP_CHECKLOCKTIMEVERIFY option (aka OP_HODL) is the answer. I have been experimenting with the "Time Locked Address" functionality on coinb.in (via TestNet) and it works as advertised. The only caveat being that you will need to use coinb.in in the future to generate and sign the spending transaction, as I don't seem to be able to get it working properly with Bitcoin Core (but that might be something I'm doing wrong)
NOTE: for the purposes of this tutorial, I have used a TestNet address and that the coinb.in code requires
some tweaking to automatically retrieve the UTXOs for TestNet addresses.
Step 1 - Get a private key- You want this in WIF format.
- You can use one from an existing wallet, but be warned, you will need to put this into coinb.in to be able to sign the spending transaction later.
Example (TestNet) PrivKey in WIF format:
cQxRyfN5wBmDAc4tX1kP2bDZ5A3woXsayc1VLXu74WVc7ukmqQb6
Step 2 - Get the public key that matches your private key- you need the hex public key, NOT the address
Example Hex Pubkey matching PrivKey:
032371229be41fd3d89d5dddd02cdfbcafbea07ec25ff2e8d9db1c8cd5983361bc
Step 3 - Create the "Time Locked Address":- You can do this here:
https://coinb.in/#newTimeLocked - Alternatively, you can download the coinb.in code base and run it offline
- Enter the hex public key from Step 2, and pick the date/time you want the address to be locked to.
- Click "Submit"
Step 4 - Note down the "Time Locked Address" and "Redeem Script":Example TLA:
2NAkEGEghkTs5BGn9kgK2PbMhaE2gThPgA3
Example Redeem Script:
04e056a55fb17521032371229be41fd3d89d5dddd02cdfbcafbea07ec25ff2e8d9db1c8cd598336
1bcac
Step 5 - Send funds to the "Time Locked Address"- This is just a "standard" transaction
- Send using whatever wallet/fee etc. that you find appropriate.
Example Funding Transaction:
64ad87ac7789eae5190b8e76570ca6ad350ffccf1a5f59af0ae774dbde190a25Step 6 (Optional) - Try and send "locked" funds6.a: - Load "Inputs":
- Visit
https://coinb.in/#newTransaction (or use your downloaded, offline version)
- Enter redeem script and click "Load" (won't work with "offline" mode)
- Click the "Inputs" tab
- You should get the UTXO(s) in your locked address loaded:
6.b: - Create "Outputs":
- Click on the "outputs" tab
- Enter the receive address and amount you want to send (
IMPORTANT NOTE: any amount you don't specify in outputs, will be used as the TOTAL fee!!)
You can see I specified an output of 0.01999700... the difference between that and the total input (0.02) is going to be used as the total fee amount (0.00000300)... Unfortunately, there isn't a way to specify a fee rate, you need to work it out yourself... these "Legacy" transactions end up being around ~200 bytes... so my total fee of 300, ends up being around 1.5 sats/byte. Pretty low, but testnet is forgiving like that
6.c: - Get
unsigned transaction:
- Once you're happy with the outputs and fee, click Submit:
Example raw unsigned transaction:
0100000001250a19dedb74e70aaf595f1acffc0f35ada60c57768e0b19e5ea8977ac87ad64010000002a04e056a55fb17521032371229be41fd3d89d5dddd02cdfbcafbea07ec25ff2e8d9db1c8cd5983361bcacfdffffff0154831e00000000001976a91444cb040fe56b0f22411da75b1458ac8864802bfb88ace056a55f
6.d (Optional, but recommended): - Verify your transaction:
-
https://coinb.in/#verify- Enter your unsigned transaction and click submit
Double check that everything is in order
6.e - Sign the transaction:
- Enter the unsigned transaction
- Enter the private key from Step #1
- Click Submit
As per the note, make sure to double check that your fee rate is going to be OK... in this example... size = 200, fee was 300... 300/200 = 1.5 sats/byte. If you screwed up the fee rate, you can simply go back and start Step 6 again, and use a higher fee... the transaction should end up being about the same size (maybe 1 or 2 bytes in either direction), so you should be able to calculate it easily the 2nd time round
6.f - (Try) Broadcast the transaction:
- I tried to broadcast before locktime using the BlockStream Explorer (
https://blockstream.info/testnet/tx/push):
and using Bitcoin Core:
Congrats... your funds are now
LOCKED!
Step 7 - Broadcast once the timelock has expired:- Now we just repeat Step 6 again, but broadcast AFTER the locktime has passed, and we can see that the transaction was a success:
2972b09a1f0f52d8810368acc894cc6b2af6a1a7ae23e73d89aec68ddf6dd8ae
Personally, I would just go with the nLocktime solution.
nLocktime is the last 4 bytes of all the transactions. what you meant was the lock time OP codes.
That is indeed what I meant... I just typed the wrong thing... this is what happens when you try to be clever after midnight!
I've edited my post to reflect that.