0

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.

1

See What does the sequence in a transaction input mean?

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

6
  • 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
    May 11 '20 at 12:23
  • I updated my answer, does that help?
    – pinhead
    May 11 '20 at 12:40
  • 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
    May 11 '20 at 14:49
  • What is the nLocktime of the TX? bitcoin.stackexchange.com/questions/88289/…
    – pinhead
    May 11 '20 at 15:43
  • 00000000, I need to change nLocktine If I use CLTV, Or I mistake?
    – monkeyUser
    May 11 '20 at 16:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.