<p>You have to add the <code>absolute time/blockheight</code> before OP_CHECKLOCKTIMEVERIFY in the script to depict how long you want to lock the transaction. Also you are using 150 as the CLTV parameter. Anything that is below 500M is dubbed as block height. Given you are using 150, that means that transaction is not spendable until 150 blocks, which should mean it is spendable immediately.</p>

CC BY-SA 4.0
2019-04-12T15:36:52.840Z
I use regtest and I reset the chain to test it. So, 150 blocks haven't reached yet. As for the `OP_CHECKLOCKTIMEVERIFY` isn't the `seq.for_script()` which is before that do the trick? Since the `seq` has the `absolute time/blockheight`
Tasos
CC BY-SA 4.0
2019-04-12T15:48:10.883Z
No. nSequnce has different meaning for CLTV. If nSequence value is >=2^31 it indicates that CLTV, or opt-in-replace is used. However, if nSequence value <2^31, it indicates CSV. nSequence value should however not be 0xffffffff when using cltv
Ugam Kamat
CC BY-SA 4.0
2019-04-12T15:52:00.000Z
So, to understand, it should be replaced with an integer for the absolute height like that? `script = Script([150, 'OP_CHECKLOCKTIMEVERIFY', 'OP_DROP', 'OP_DUP', 'OP_HASH160', p2pkh_addr.to_hash160(),  'OP_EQUALVERIFY', 'OP_CHECKSIG'])`
Tasos
CC BY-SA 4.0
2019-04-12T16:04:09.437Z
Unsure about the exact syntax, but think that should work.
Ugam Kamat
CC BY-SA 4.0
2019-04-12T14:43:17.250Z
2019-04-12T14:43:17.250Z
Ugam Kamat
<p>I am new in Bitcoin and I try to create an address in Bitcoind and send a transaction that the amount will be spendable in a specific height of the blockchain.</p>

<p>Here is what I have done:</p>

<pre><code>privateKey = 'cS5bZo8D1PBXwLbpGwYpb3CPvev5FYA7zPpftXAc6vzvbXt3aAa4'

absolute_time = 150

addr = getAddressFromPriv(privateKey) #customFunction

seq = Sequence(TYPE_ABSOLUTE_TIMELOCK, absolute_time)

script = Script([seq.for_script(), 
                        'OP_CHECKLOCKTIMEVERIFY', 
                        'OP_DROP', 
                        'OP_DUP', 
                        'OP_HASH160', 
                        p2pkh_addr.to_hash160(), 
                        'OP_EQUALVERIFY', 
                        'OP_CHECKSIG'])

addr2 = convertScriptToAddress(script) 
</code></pre>

<p>Then in bitcoin-cli I use that addr2 to <code>bitcoin-cli sendtoaddress &lt;addr2&gt; 10</code></p>

<p>However, when I inspect the transaction it says that it is spendable in the current block height. Any idea?</p>

CC BY-SA 4.0
2019-04-12T10:43:38.753Z
Shouldn't you add the <absolute time/blockheight> before OP_CHECKLOCKTIMEVERIFY in the script? Also you are using 150 as the block height, which means it should be spendable immediately.
Ugam Kamat
CC BY-SA 4.0
2019-04-12T14:02:37.217Z
@UgamKamat: I think you're on to it, but please don't use comments to answer a question, rather post an answer. You can always edit your answer as the topic evolves.
Murch
CC BY-SA 4.0
2019-04-12T14:41:01.270Z
Yeah, wasn't totally sure. So wanted @Tasos to check if that works. Writing it as an answer.
Ugam Kamat
<bitcoind><python><bitcoin-cli><regtest><locktime>
Create a transaction spendable in a specific block height
Tasos
# Create a transaction spendable in a specific block height

(Asked by: username_0 on 2019-04-12)

I am new in Bitcoin and I try to create an address in Bitcoind and send a transaction that the amount will be spendable in a specific height of the blockchain.
Here is what I have done:
privateKey = 'cS5bZo8D1PBXwLbpGwYpb3CPvev5FYA7zPpftXAc6vzvbXt3aAa4'

absolute_time = 150

addr = getAddressFromPriv(privateKey) #customFunction

seq = Sequence(TYPE_ABSOLUTE_TIMELOCK, absolute_time)

script = Script([seq.for_script(), 
                        'OP_CHECKLOCKTIMEVERIFY', 
                        'OP_DROP', 
                        'OP_DUP', 
                        'OP_HASH160', 
                        p2pkh_addr.to_hash160(), 
                        'OP_EQUALVERIFY', 
                        'OP_CHECKSIG'])

addr2 = convertScriptToAddress(script) 

Then in bitcoin-cli I use that addr2 to bitcoin-cli sendtoaddress  10
However, when I inspect the transaction it says that it is spendable in the current block height. Any idea?

**Tags:** bitcoind, python, bitcoin-cli, regtest, locktime

> **Comments:**
> **username_1**: Shouldn't you add the <absolute time/blockheight> before OP_CHECKLOCKTIMEVERIFY in the script? Also you are using 150 as the block height, which means it should be spendable immediately.  
> **username_2**: @UgamKamat: I think you're on to it, but please don't use comments to answer a question, rather post an answer. You can always edit your answer as the topic evolves.  
> **username_1**: Yeah, wasn't totally sure. So wanted @username_0 to check if that works. Writing it as an answer.  

---

## 1 answers

### Answer by username_1 on 2019-04-12. Score: 1 | Accepted answer

You have to add the `absolute time/blockheight` before OP\_CHECKLOCKTIMEVERIFY in the script to depict how long you want to lock the transaction. Also you are using 150 as the CLTV parameter. Anything that is below 500M is dubbed as block height. Given you are using 150, that means that transaction is not spendable until 150 blocks, which should mean it is spendable immediately.

> **Comments:**
> **username_0**: I use regtest and I reset the chain to test it. So, 150 blocks haven't reached yet. As for the `OP_CHECKLOCKTIMEVERIFY` isn't the `seq.for_script()` which is before that do the trick? Since the `seq` has the `absolute time/blockheight`  
> **username_1**: No. nSequnce has different meaning for CLTV. If nSequence value is >=2^31 it indicates that CLTV, or opt-in-replace is used. However, if nSequence value <2^31, it indicates CSV. nSequence value should however not be 0xffffffff when using cltv  
> **username_0**: So, to understand, it should be replaced with an integer for the absolute height like that? `script = Script([150, 'OP_CHECKLOCKTIMEVERIFY', 'OP_DROP', 'OP_DUP', 'OP_HASH160', p2pkh_addr.to_hash160(),  'OP_EQUALVERIFY', 'OP_CHECKSIG'])`  
> **username_1**: Unsure about the exact syntax, but think that should work.  

---

