<p>I have created a P2sh includes <strong>OP_CHECKSEQUENCEVERIFY</strong> and funded the same. I was trying to redeem the coins. But i could not understand the working of OP_CHECKSEQUENCEVERIFY.
Below is the example which I have tried, </p>

<p><strong>Execute the timelock condn:</strong>
currently the <strong>block count is 152</strong></p>

<p>btcc [<code>OP_IF 155 OP_CHECKSEQUENCEVERIFY OP_DROP OP_SHA256 ef7797e13d3a75526946a3bcf00daec9fc9c9c4d51ddc7cc5df888f74dd434d1 OP_EQUAL OP_ENDIF</code>]</p>

<p><strong>redeemscript:</strong></p>

<pre><code>    2a63029b00b275a820ef7797e13d3a75526946a3bcf00daec9fc9c9c4d51ddc7cc5df888f74dd434d18768
</code></pre>

<pre><code>bitcoin-cli decodescript 63029b00b275a820ef7797e13d3a75526946a3bcf00daec9fc9c9c4d51ddc7cc5df888f74dd434d18768

{
  "asm": "OP_IF 155 OP_CHECKSEQUENCEVERIFY OP_DROP OP_SHA256 ef7797e13d3a75526946a3bcf00daec9fc9c9c4d51ddc7cc5df888f74dd434d1 OP_EQUAL OP_ENDIF",
  "type": "nonstandard",
  "p2sh": "2N8grZYRHeBLPy9hE7LoY6MvS53j81UYcpP",
  "segwit": {
    "asm": "0 204808939e268852417e8d2988688fbb7482887aa3ecb10e46e848427976bd77",
    "hex": "0020204808939e268852417e8d2988688fbb7482887aa3ecb10e46e848427976bd77",
    "reqSigs": 1,
    "type": "witness_v0_scripthash",
    "addresses": [
      "bcrt1qypyq3yu7y6y9yst7355cs6y0hd6g9zr650ktzrjxapyyy7tkh4mshxnqjw"
    ],
    "p2sh-segwit": "2NFRd4rwoGkRy13fA4h2DhmHrAUgJ1rx5cr"
  }
}


bitcoin-cli sendtoaddress 2N8grZYRHeBLPy9hE7LoY6MvS53j81UYcpP 0.001
4383cef8bb9026ec5a0a7ee0be4379b5d888bddbbf328ed2c356941fb0e2a4af
</code></pre>

<p><strong>create raw txn with below given txid and vout:</strong></p>

<pre><code>bitcoin-cli getrawtransaction 4383cef8bb9026ec5a0a7ee0be4379b5d888bddbbf328ed2c356941fb0e2a4af
02000000000101fc4d29e944c0efb5aad0e437dc13a0bba3374ae885673879b213c6dc80c021350000000017160014544aa5cc9c1377f5bc51240216d0dfbcd0809efdfeffffff02c4bb25050000000017a9145b5337c2a79e2f3c01185eaca7f1322eff343fb087a08601000000000017a914a962d0d582a9ffe4f4ffeef878ced14b381a3daa870247304402206c9c3af6dedd715b21037e53b7212d4228fb75b7e7c9b136511f46a35dadcdda0220499b18337235323bd558cbf0b91ed0a73ff56373c312fccd69e5866ba1662cf1012103ba91e8963545b487403bf7b325598b896dbd6e6e858f9b8fd053576033f114c198000000

</code></pre>

<p>Some parts of o/p:</p>

<p><strong>txid:</strong> 4383cef8bb9026ec5a0a7ee0be4379b5d888bddbbf328ed2c356941fb0e2a4af</p>

<p><strong>vout:</strong>
{</p>

<p>"value": 0.00100000,
  "n": 1,
  "scriptPubKey": {
    "asm": "OP_HASH160 a962d0d582a9ffe4f4ffeef878ced14b381a3daa OP_EQUAL",
    "hex": "a914a962d0d582a9ffe4f4ffeef878ced14b381a3daa87",
    "reqSigs": 1,
    "type": "scripthash",
    "addresses": [
      "2N8grZYRHeBLPy9hE7LoY6MvS53j81UYcpP"
    ]
  }
}</p>

<pre><code>bitcoin-cli createrawtransaction "[{\"txid\":\"4383cef8bb9026ec5a0a7ee0be4379b5d888bddbbf328ed2c356941fb0e2a4af\",\"vout\":1}]" "[{\"mtrNo3QBMwXRV5HdxknBesWBzitqEnfLxM\":0.0003},{\"2N8grZYRHeBLPy9hE7LoY6MvS53j81UYcpP\":0.000688}]"
</code></pre>

<p><strong>o/p:</strong></p>

<pre><code>0200000001afa4e2b01f9456c3d28e32bfdbbd88d8b57943bee07e0a5aec2690bbf8ce83430100000000ffffffff0230750000000000001976a9149245fd67a780afdd93ae3e8d39cdc41b40deeeaa88acc00c01000000000017a914a962d0d582a9ffe4f4ffeef878ced14b381a3daa8700000000
</code></pre>

<p><strong>adding the signature:</strong></p>

<p><strong>ScriptSig part:</strong></p>

<p><strong>secret hex:</strong> <code>0a626c6f636b636861696e</code></p>

<p><strong>redeemscript:</strong></p>

<pre><code>2a63029b00b275a820ef7797e13d3a75526946a3bcf00daec9fc9c9c4d51ddc7cc5df888f74dd434d18768
</code></pre>

<p>secrethash + if condn+ redeem script</p>

<pre><code>0a626c6f636b636861696e01512a63029b00b275a820ef7797e13d3a75526946a3bcf00daec9fc9c9c4d51ddc7cc5df888f74dd434d18768
</code></pre>

<p><strong>manually created signature:</strong></p>

<pre><code>0200000001afa4e2b01f9456c3d28e32bfdbbd88d8b57943bee07e0a5aec2690bbf8ce834301000000380a626c6f636b636861696e01512a63029b00b275a820ef7797e13d3a75526946a3bcf00daec9fc9c9c4d51ddc7cc5df888f74dd434d18768ffffffff0230750000000000001976a9149245fd67a780afdd93ae3e8d39cdc41b40deeeaa88acc00c01000000000017a914a962d0d582a9ffe4f4ffeef878ced14b381a3daa8700000000






bitcoin-cli sendrawtransaction 0200000001afa4e2b01f9456c3d28e32bfdbbd88d8b57943bee07e0a5aec2690bbf8ce834301000000380a626c6f636b636861696e01512a63029b00b275a820ef7797e13d3a75526946a3bcf00daec9fc9c9c4d51ddc7cc5df888f74dd434d18768ffffffff0230750000000000001976a9149245fd67a780afdd93ae3e8d39cdc41b40deeeaa88acc00c01000000000017a914a962d0d582a9ffe4f4ffeef878ced14b381a3daa8700000000
</code></pre>

<p><strong>error code: -26
error message:
non-mandatory-script-verify-flag (Locktime requirement not satisfied) (code 64)</strong></p>

<p>the same error , was getting even if the <strong>blocksize reached more than 155.</strong> </p>

<p>Can you please explain to me what I have missed?</p>

CC BY-SA 4.0
2019-09-30T16:50:16.020Z
I would like to replicate what you're doing: could you please edit in the result of `bitcoin-cli getrawtransaction 4383cef8bb9026ec5a0a7ee0be4379b5d888bddbbf328ed2c356941fb0e2a4af`
Alistair Mann
CC BY-SA 4.0
2019-10-01T05:52:04.487Z
@AlistairMann edited.
kitty
CC BY-SA 4.0
2019-10-01T06:00:32.280Z
@kitty you have set `nSequence` of your transaction to default, which is 4294967295. When redeeming OP_CSV, your nSequence should be higher than the blocks locked in OP_CSV, but lower than the number of blocks that have been mined since the transaction was confirmed in the block. You can set your `nSequence` to 155 in the `createrawtransaction` step.
Ugam Kamat
CC BY-SA 4.0
2019-10-01T13:40:49.303Z
Hi @UgamKamat , could not understand properly. Say my block size 155, in the script condition is for 160 then what can be set to sequence value to redeem the coins? When you are mentioning the nsequence should be greater than the blocks locked in CSV (i.e script) and should be less than blocks mined (block size). It sounds contradictory. Can you please give some clarification on this? When I changed the seqeunce value to a specified value, I m getting error as error code: -26
error message:
non-BIP68-final (code 64)
kitty
CC BY-SA 4.0
2019-10-01T16:05:02.450Z
@kitty 1/2 for example, let us assume that you locked the bitcoins in CSV output for 155 blocks and was mined in a block at height N. Now, after some elapsed time the current height of the blockchain is N+166. Since 166 blocks have passed you can spend that locked output. However, you have to indicate that by setting the `nSequence` value. This value has to be more than 155, but less than 166 in our case. If we set it more than 166, the software will detect that the value of `nSequence` is higher than the number of blocks have passed and reject the transaction.
Ugam Kamat
CC BY-SA 4.0
2019-10-01T16:07:17.777Z
2/2 However also note that setting `nSequence` value `0xffffffff` (which is in your case) disables relative locktime. you can refer to my [answer](https://bitcoin.stackexchange.com/questions/87372/what-does-the-sequence-in-a-transaction-input-mean/87376#87376) for more info on CSV and nSequence
Ugam Kamat
CC BY-SA 4.0
2019-10-01T17:21:45.683Z
Thank you @UgamKamat. How did you calculate 166 for 155?
kitty
CC BY-SA 4.0
2019-10-01T17:43:49.103Z
@kitty blockheight of N+166 (i assumed 166 blocks have been mined since your transaction was confirmed in a block.)
Ugam Kamat
<bitcoind><script><p2sh><input-script><checksequenceverify>
How to use "OP_CHECKSEQUENCEVERIFY" in regtest?
kitty
# How to use "OP_CHECKSEQUENCEVERIFY" in regtest?

(Asked by: username_0 on 2019-09-30)

I have created a P2sh includes **OP\_CHECKSEQUENCEVERIFY** and funded the same. I was trying to redeem the coins. But i could not understand the working of OP\_CHECKSEQUENCEVERIFY.
Below is the example which I have tried,

**Execute the timelock condn:**
currently the **block count is 152**

btcc [`OP_IF 155 OP_CHECKSEQUENCEVERIFY OP_DROP OP_SHA256 ef7797e13d3a75526946a3bcf00daec9fc9c9c4d51ddc7cc5df888f74dd434d1 OP_EQUAL OP_ENDIF`]

**redeemscript:**

```
    2a63029b00b275a820ef7797e13d3a75526946a3bcf00daec9fc9c9c4d51ddc7cc5df888f74dd434d18768

```

```
bitcoin-cli decodescript 63029b00b275a820ef7797e13d3a75526946a3bcf00daec9fc9c9c4d51ddc7cc5df888f74dd434d18768

{
  "asm": "OP_IF 155 OP_CHECKSEQUENCEVERIFY OP_DROP OP_SHA256 ef7797e13d3a75526946a3bcf00daec9fc9c9c4d51ddc7cc5df888f74dd434d1 OP_EQUAL OP_ENDIF",
  "type": "nonstandard",
  "p2sh": "2N8grZYRHeBLPy9hE7LoY6MvS53j81UYcpP",
  "segwit": {
    "asm": "0 204808939e268852417e8d2988688fbb7482887aa3ecb10e46e848427976bd77",
    "hex": "0020204808939e268852417e8d2988688fbb7482887aa3ecb10e46e848427976bd77",
    "reqSigs": 1,
    "type": "witness_v0_scripthash",
    "addresses": [
      "bcrt1qypyq3yu7y6y9yst7355cs6y0hd6g9zr650ktzrjxapyyy7tkh4mshxnqjw"
    ],
    "p2sh-segwit": "2NFRd4rwoGkRy13fA4h2DhmHrAUgJ1rx5cr"
  }
}

bitcoin-cli sendtoaddress 2N8grZYRHeBLPy9hE7LoY6MvS53j81UYcpP 0.001
4383cef8bb9026ec5a0a7ee0be4379b5d888bddbbf328ed2c356941fb0e2a4af

```

**create raw txn with below given txid and vout:**

```
bitcoin-cli getrawtransaction 4383cef8bb9026ec5a0a7ee0be4379b5d888bddbbf328ed2c356941fb0e2a4af
02000000000101fc4d29e944c0efb5aad0e437dc13a0bba3374ae885673879b213c6dc80c021350000000017160014544aa5cc9c1377f5bc51240216d0dfbcd0809efdfeffffff02c4bb25050000000017a9145b5337c2a79e2f3c01185eaca7f1322eff343fb087a08601000000000017a914a962d0d582a9ffe4f4ffeef878ced14b381a3daa870247304402206c9c3af6dedd715b21037e53b7212d4228fb75b7e7c9b136511f46a35dadcdda0220499b18337235323bd558cbf0b91ed0a73ff56373c312fccd69e5866ba1662cf1012103ba91e8963545b487403bf7b325598b896dbd6e6e858f9b8fd053576033f114c198000000

```

Some parts of o/p:

**txid:** 4383cef8bb9026ec5a0a7ee0be4379b5d888bddbbf328ed2c356941fb0e2a4af

**vout:**
{

"value": 0.00100000,
"n": 1,
"scriptPubKey": {
"asm": "OP\_HASH160 a962d0d582a9ffe4f4ffeef878ced14b381a3daa OP\_EQUAL",
"hex": "a914a962d0d582a9ffe4f4ffeef878ced14b381a3daa87",
"reqSigs": 1,
"type": "scripthash",
"addresses": [
"2N8grZYRHeBLPy9hE7LoY6MvS53j81UYcpP"
]
}
}

```
bitcoin-cli createrawtransaction "[{\"txid\":\"4383cef8bb9026ec5a0a7ee0be4379b5d888bddbbf328ed2c356941fb0e2a4af\",\"vout\":1}]" "[{\"mtrNo3QBMwXRV5HdxknBesWBzitqEnfLxM\":0.0003},{\"2N8grZYRHeBLPy9hE7LoY6MvS53j81UYcpP\":0.000688}]"

```

**o/p:**

```
0200000001afa4e2b01f9456c3d28e32bfdbbd88d8b57943bee07e0a5aec2690bbf8ce83430100000000ffffffff0230750000000000001976a9149245fd67a780afdd93ae3e8d39cdc41b40deeeaa88acc00c01000000000017a914a962d0d582a9ffe4f4ffeef878ced14b381a3daa8700000000

```

**adding the signature:**

**ScriptSig part:**

**secret hex:** `0a626c6f636b636861696e`

**redeemscript:**

```
2a63029b00b275a820ef7797e13d3a75526946a3bcf00daec9fc9c9c4d51ddc7cc5df888f74dd434d18768

```

secrethash + if condn+ redeem script

```
0a626c6f636b636861696e01512a63029b00b275a820ef7797e13d3a75526946a3bcf00daec9fc9c9c4d51ddc7cc5df888f74dd434d18768

```

**manually created signature:**

```
0200000001afa4e2b01f9456c3d28e32bfdbbd88d8b57943bee07e0a5aec2690bbf8ce834301000000380a626c6f636b636861696e01512a63029b00b275a820ef7797e13d3a75526946a3bcf00daec9fc9c9c4d51ddc7cc5df888f74dd434d18768ffffffff0230750000000000001976a9149245fd67a780afdd93ae3e8d39cdc41b40deeeaa88acc00c01000000000017a914a962d0d582a9ffe4f4ffeef878ced14b381a3daa8700000000

bitcoin-cli sendrawtransaction 0200000001afa4e2b01f9456c3d28e32bfdbbd88d8b57943bee07e0a5aec2690bbf8ce834301000000380a626c6f636b636861696e01512a63029b00b275a820ef7797e13d3a75526946a3bcf00daec9fc9c9c4d51ddc7cc5df888f74dd434d18768ffffffff0230750000000000001976a9149245fd67a780afdd93ae3e8d39cdc41b40deeeaa88acc00c01000000000017a914a962d0d582a9ffe4f4ffeef878ced14b381a3daa8700000000

```

**error code: -26
error message:
non-mandatory-script-verify-flag (Locktime requirement not satisfied) (code 64)**

the same error , was getting even if the **blocksize reached more than 155.**

Can you please explain to me what I have missed?

**Tags:** bitcoind, script, p2sh, input-script, checksequenceverify

> **Comments:**
> **username_1**: I would like to replicate what you're doing: could you please edit in the result of `bitcoin-cli getrawtransaction 4383cef8bb9026ec5a0a7ee0be4379b5d888bddbbf328ed2c356941fb0e2a4af`  
> **username_0**: @username_1 edited.  
> **username_2**: @username_0 you have set `nSequence` of your transaction to default, which is 4294967295. When redeeming OP_CSV, your nSequence should be higher than the blocks locked in OP_CSV, but lower than the number of blocks that have been mined since the transaction was confirmed in the block. You can set your `nSequence` to 155 in the `createrawtransaction` step.  
> **username_0**: Hi @username_2 , could not understand properly. Say my block size 155, in the script condition is for 160 then what can be set to sequence value to redeem the coins? When you are mentioning the nsequence should be greater than the blocks locked in CSV (i.e script) and should be less than blocks mined (block size). It sounds contradictory. Can you please give some clarification on this? When I changed the seqeunce value to a specified value, I m getting error as error code: -26 error message: non-BIP68-final (code 64)  
> **username_2**: @username_0 1/2 for example, let us assume that you locked the bitcoins in CSV output for 155 blocks and was mined in a block at height N. Now, after some elapsed time the current height of the blockchain is N+166. Since 166 blocks have passed you can spend that locked output. However, you have to indicate that by setting the `nSequence` value. This value has to be more than 155, but less than 166 in our case. If we set it more than 166, the software will detect that the value of `nSequence` is higher than the number of blocks have passed and reject the transaction.  
> **username_2**: 2/2 However also note that setting `nSequence` value `0xffffffff` (which is in your case) disables relative locktime. you can refer to my [answer](https://bitcoin.stackexchange.com/questions/87372/what-does-the-sequence-in-a-transaction-input-mean/87376#87376) for more info on CSV and nSequence  
> **username_0**: Thank you @username_2. How did you calculate 166 for 155?  
> **username_2**: @username_0 blockheight of N+166 (i assumed 166 blocks have been mined since your transaction was confirmed in a block.)  

---

## 0 answers

