36

I'm currently trying to generate the genesis block with my code and I've stumbled upon the TxIn sequence field that is not explained in the Protocol Specification wiki page, nor does it seem to appear in the block explorer. What is the way the value of this field is calculated, and what was its value for the genesis block?

2 Answers 2

34

Sequence numbers aren't shown on the Bitcoin Block Explorer HTML pages because they are not used by the network currently. Non-default sequence numbers would be shown on raw block/tx pages, but I'm not sure whether this has ever happened.

Sequence numbers are intended to be used for replacement. Replacement is currently disabled, but how it would work is:

  • You send a transaction with a LockTime in the future and a sequence number of 0. The transaction is then not considered by the network to be "final", and it can't be included in a block until the specified LockTime is reached.
  • Before LockTime expires, you can replace the transaction with as many new versions as you want. Newer versions have higher sequence numbers.
  • If you ever want to lock the transaction permanently, you can set the sequence number to UINT_MAX. Then the transaction is considered to be final, even if LockTime has not been reached.

This is useful in several cases. For example, two parties can use it to set up a "prepared transaction". Once the prepared transaction is created, the parties can move money between each other instantly, securely, and without fees. So you could set one of these up with an exchange and withdraw and deposit without waiting for confirmations.

Since replacement is not used currently, all transactions Bitcoin creates have LockTime = 0 and Sequence = UINT_MAX. This is the case with the genesis block's generation transaction.

6
  • 3
    How does the network determine whether to accept a new version as a replacement transaction? Could an attacker replace transactions maliciously?
    – jl6
    Dec 23, 2011 at 16:54
  • 5
    Non-default sequence numbers have happened. Once in January 2011 and 6 times in February 2011. The sequence number was zero in each case. See transaction c99c49da4c38af669dea436d3e73780dfdb6c1ecf9958baa52960e8baee30e73 for an example. blockexplorer.com/rawtx/… Feb 11, 2012 at 4:38
  • 1
    For reference UINT_MAX = 4294967295U Mar 8, 2014 at 6:12
  • 3
    Your answer seems to assume that a transaction has a single sequence number, but according to the protocol specification, a transaction will have a sequence number per each input. In this case, I'm not sure how replacement would work. Consider a transaction with two inputs: input #0 has seqno 1 and input #1 has seqno 2. How would this transaction be compared to one where input #0 has seqno 2 and input #1 has seqno 1? Feb 15, 2017 at 14:30
  • UINT_MAX is a 32 bit value. In hex it is "FFFFFFFF". Feb 19, 2018 at 13:40
28

Note that the accepted answer is outdated.

Currently, sequence numbers are mainly used for signaling RBF - replace-by-fee - that allows you to resend a transaction with a higher fee.

See https://bitcoincore.org/en/faq/optin_rbf/ , https://github.com/bitcoin/bips/blob/master/bip-0125.mediawiki

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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