pull down to refresh

BIP-68: Relative LockTime using nSequence

Bitcoin Has Two Types of Time-Based Transactions:

  1. Relative LockTime:
    • Transaction is locked for a period after the input is confirmed
    • Example: “Spendable 100 blocks after confirmation.”
  2. Absolute LockTime:
    • Transaction is locked until a specific time or block
    • Example: “Spendable after block 800,000.”
Today we wil cover nSequence 👇

Understanding nSequence

Every Bitcoin input has a sequence field, which can delay spending.
It makes the input unspendable for a set time after its corresponding output is confirmed.

How nSequence Works?

Let’s take this scenario:
Bob wants to send Alice 10 BTC but wants to ensure she cannot spend it until 3 days after confirmation.
  1. Initial Transaction:
    • Bob receives 10 BTC in a confirmed transaction.
  2. Bob Creates a New Transaction:
    • He signs a transaction sending 10 BTC to Alice.
    • He sets nSequence = 3 days (~432 blocks).
  3. Effect of nSequence:
    • Alice cannot spend the BTC before 3 days.
    • If she tries earlier, the network rejects the transaction.
    • After 3 days, Alice can spend the BTC freely.

How to Define a Sequence Number?

1. Disabled Flag (Bit 31)

  • If set: BIP-68 is disabled, meaning nSequence has no effect.
  • If not set: BIP-68 is enabled, allowing relative lock-time.

2. Type Flag (Bit 22)

  • If set: The sequence number is interpreted as time-based (lock-time in seconds).
  • If not set: The sequence number is block-based (lock-time in block height).

3. Value (Bits 0-15)

  • Represents the actual relative lock-time value, either in blocks (if Type Flag is not set) or in time units (if Type Flag is set).

Next Post we will cover BIP 112- CSV Transaction
reply
Great explaination.thanks
reply