11 - nSequence
Last updated
Last updated
The nSequence field is a 4 byte little endian number that is the sequence number of the input. This value can be used with nLocktime to put transactions into a non-final state, allowing a managed transfer of data to take place.
In this example, we will extract the nSequence value of this input and only allow the UTXO to be spent if it is final.
<r_tx_preimg>
...
Version, hash_prevouts, hash_nSequence, hash_outpoints, script and value have been removed
<r_tx_preimg>
OP_4
nSequence length is 4 bytes long
<r_tx_preimg> 0x04
OP_SPLIT
Split nSequence
<nsequence> <rr_tx_preimg>
OP_SWAP
Move to top of stack
<rr_tx_preimg> <nsequence>
0xFFFFFFFF
0xFFFFFFFF is final
<rr_tx_preimg> <nsequence> 0xFFFFFFFF
OP_EQUALVERIFY
Fail script if tx is non-final
<r_tx_preimg>
...
rest of script