<p>See <a href="https://bitcoin.stackexchange.com/questions/87372/what-does-the-sequence-in-a-transaction-input-mean/87376#87376">What does the sequence in a transaction input mean?</a></p>

<p>1) You need to set bit 22 in the <code>nSequence</code> to indicate the value is a timestamp, not a number of bocks.</p>

<p>2) You are trying to put an absolute timestamp into nSequence, but nSequence is used for <em>relative</em> time.</p>

<p>So if you want the relative timelock to be 512 seconds, your nSequence should be:</p>

<p><code>1 |= (1 &lt;&lt; 22)</code></p>

<p>or <code>4194305</code></p>

CC BY-SA 4.0
2020-05-11T12:23:20.890Z
thanks for reply, I can't put hex formato in createrawtransaction, I need to use number. I tried even with `0x00400001` (512 seconds) But without lucky
monkeyUser
CC BY-SA 4.0
2020-05-11T12:40:40.343Z
I updated my answer, does that help?
pinhead
CC BY-SA 4.0
2020-05-11T14:49:34.933Z
thanks again. I tried with 4194305 or with 4194312 (more time) But I can send the transaction immediately `bitcoin-cli createrawtransaction '[{"txid":"'$TXID'","vout":'$VOUT',"sequence":4194314}]' '[{"'$ADDR_DEST'":'$AMOUNT'}]'`
monkeyUser
CC BY-SA 4.0
2020-05-11T15:43:43.060Z
What is the nLocktime of the TX? https://bitcoin.stackexchange.com/questions/88289/what-is-transaction-finality
pinhead
CC BY-SA 4.0
2020-05-11T16:05:37.953Z
00000000, I need to change nLocktine If I use CLTV, Or I mistake?
monkeyUser
CC BY-SA 4.0
2020-05-11T17:37:04.770Z
read the question I just posted and make sure you understand the difference between nSequence and nLockTime. Your question is about relative locktime so I assume CLTV is not invovled.
pinhead
CC BY-SA 4.0
2020-05-11T12:19:48.517Z
2020-05-11T12:39:57.020Z
2020-05-11T12:39:57.020Z
pinhead
<p>I'm studying how Timelock works.
I'm able to create transaction with absolute time, <code>nLocktime</code> and <code>OP_CLTV</code>. Now I want to understand the relative part, and I start with <code>nSequence</code>.</p>

<p>At the moment I use <code>createrawtransaction</code> to create my raw transaction, where</p>

<pre><code>bitcoin-cli createrawtransaction '[{"txid":"'$TXID'","vout":'$VOUT',"sequence":'$TIME'}]' '[{"'$ADDR_DEST'":'$AMOUNT'}]'
</code></pre>

<p>Where $TIME is:</p>

<pre><code>$ gdate --date 'now + 512 seconds' +%s
1589189045
</code></pre>

<p>Human Readable: <code>Mon May 11 11:08:44 CEST 2020</code> </p>

<p>I mined some blocks and my median time is <code>Mon May 11 11:13:05 CEST 2020</code>, When I try to send my Transaction I get this error: </p>

<pre><code>error code: -26
error message:
non-BIP68-final (code 64)
</code></pre>

<p>Here my raw transaction</p>

<pre><code>020000000001012d343a729ac2addc97ebdfd6e086b4c31060546b51134f208360fb2e3989c9cc00000000001c16b95e016036f829010000001600147163053fa92512e2fb2004e9173e564bbdeb8ed40247304402203cd801bc04a71e14b08445357a2f542758cc0cf32f573a6e5489109bfa31a5b90220429c3aa40e670d1fdfee5e8f910604a3c9aa7e656e886dd8ba2591e6f22787440121037bc7eb8a954817f1b95f55f79b0927c7f42f71d461da845c08b0858d125df23400000000 

  {
  "txid": "f6cb3d437858ea1ddd81d45c1b391d27faf1b594e65d7f0ae312fc55f67aff12",
  "hash": "b833a701caaba372cdd87e01c08c18755d40bd9fc20568571f2d45be3d219781",
  "version": 2,
  "size": 191,
  "vsize": 110,
  "weight": 437,
  "locktime": 0,
  "vin": [
    {
      "txid": "ccc989392efb6083204f13516b546010c3b486e0d6dfeb97dcadc29a723a342d",
      "vout": 0,
      "scriptSig": {
        "asm": "",
        "hex": ""
      },
      "txinwitness": [
        "304402203cd801bc04a71e14b08445357a2f542758cc0cf32f573a6e5489109bfa31a5b90220429c3aa40e670d1fdfee5e8f910604a3c9aa7e656e886dd8ba2591e6f227874401",
        "037bc7eb8a954817f1b95f55f79b0927c7f42f71d461da845c08b0858d125df234"
      ],
      "sequence": 1589188124
    }
  ],
  "vout": [
    {
      "value": 49.991,
      "n": 0,
      "scriptPubKey": {
        "asm": "0 7163053fa92512e2fb2004e9173e564bbdeb8ed4",
        "hex": "00147163053fa92512e2fb2004e9173e564bbdeb8ed4",
        "reqSigs": 1,
        "type": "witness_v0_keyhash",
        "addresses": [
          "bcrt1qw93s20afy5fw97eqqn53w0jkfw77hrk5vtmsdk"
        ]
      }
    }
  ]
}
</code></pre>

<p>The same logic works with nLocktime.</p>

<transactions><sequence>
nSequence doesn't block my transaction
monkeyUser
# nSequence doesn't block my transaction

(Asked by: username_0 on 2020-05-11)

I'm studying how Timelock works.
I'm able to create transaction with absolute time, `nLocktime` and `OP_CLTV`. Now I want to understand the relative part, and I start with `nSequence`.

At the moment I use `createrawtransaction` to create my raw transaction, where

```
bitcoin-cli createrawtransaction '[{"txid":"'$TXID'","vout":'$VOUT',"sequence":'$TIME'}]' '[{"'$ADDR_DEST'":'$AMOUNT'}]'

```

Where $TIME is:

```
$ gdate --date 'now + 512 seconds' +%s
1589189045

```

Human Readable: `Mon May 11 11:08:44 CEST 2020`

I mined some blocks and my median time is `Mon May 11 11:13:05 CEST 2020`, When I try to send my Transaction I get this error:

```
error code: -26
error message:
non-BIP68-final (code 64)

```

Here my raw transaction

```
020000000001012d343a729ac2addc97ebdfd6e086b4c31060546b51134f208360fb2e3989c9cc00000000001c16b95e016036f829010000001600147163053fa92512e2fb2004e9173e564bbdeb8ed40247304402203cd801bc04a71e14b08445357a2f542758cc0cf32f573a6e5489109bfa31a5b90220429c3aa40e670d1fdfee5e8f910604a3c9aa7e656e886dd8ba2591e6f22787440121037bc7eb8a954817f1b95f55f79b0927c7f42f71d461da845c08b0858d125df23400000000 

  {
  "txid": "f6cb3d437858ea1ddd81d45c1b391d27faf1b594e65d7f0ae312fc55f67aff12",
  "hash": "b833a701caaba372cdd87e01c08c18755d40bd9fc20568571f2d45be3d219781",
  "version": 2,
  "size": 191,
  "vsize": 110,
  "weight": 437,
  "locktime": 0,
  "vin": [
    {
      "txid": "ccc989392efb6083204f13516b546010c3b486e0d6dfeb97dcadc29a723a342d",
      "vout": 0,
      "scriptSig": {
        "asm": "",
        "hex": ""
      },
      "txinwitness": [
        "304402203cd801bc04a71e14b08445357a2f542758cc0cf32f573a6e5489109bfa31a5b90220429c3aa40e670d1fdfee5e8f910604a3c9aa7e656e886dd8ba2591e6f227874401",
        "037bc7eb8a954817f1b95f55f79b0927c7f42f71d461da845c08b0858d125df234"
      ],
      "sequence": 1589188124
    }
  ],
  "vout": [
    {
      "value": 49.991,
      "n": 0,
      "scriptPubKey": {
        "asm": "0 7163053fa92512e2fb2004e9173e564bbdeb8ed4",
        "hex": "00147163053fa92512e2fb2004e9173e564bbdeb8ed4",
        "reqSigs": 1,
        "type": "witness_v0_keyhash",
        "addresses": [
          "bcrt1qw93s20afy5fw97eqqn53w0jkfw77hrk5vtmsdk"
        ]
      }
    }
  ]
}

```

The same logic works with nLocktime.

**Tags:** transactions, sequence


---

## 1 answers

### Answer by username_1 on 2020-05-11. Score: 1 | Accepted answer

See [What does the sequence in a transaction input mean?](https://bitcoin.stackexchange.com/questions/87372/what-does-the-sequence-in-a-transaction-input-mean/87376#87376)

1) You need to set bit 22 in the `nSequence` to indicate the value is a timestamp, not a number of bocks.

2) You are trying to put an absolute timestamp into nSequence, but nSequence is used for *relative* time.

So if you want the relative timelock to be 512 seconds, your nSequence should be:

`1 |= (1 << 22)`

or `4194305`

> **Comments:**
> **username_0**: thanks for reply, I can't put hex formato in createrawtransaction, I need to use number. I tried even with `0x00400001` (512 seconds) But without lucky  
> **username_1**: I updated my answer, does that help?  
> **username_0**: thanks again. I tried with 4194305 or with 4194312 (more time) But I can send the transaction immediately `bitcoin-cli createrawtransaction '[{"txid":"'$TXID'","vout":'$VOUT',"sequence":4194314}]' '[{"'$ADDR_DEST'":'$AMOUNT'}]'`  
> **username_1**: What is the nLocktime of the TX? https://bitcoin.stackexchange.com/questions/88289/what-is-transaction-finality  
> **username_0**: 00000000, I need to change nLocktine If I use CLTV, Or I mistake?  
> **username_1**: read the question I just posted and make sure you understand the difference between nSequence and nLockTime. Your question is about relative locktime so I assume CLTV is not invovled.  

---

