> For the complete documentation index, see [llms.txt](https://hub.bsvblockchain.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hub.bsvblockchain.org/higher-learning/bsv-academy/introduction-to-bitcoin-script/chapter-5-op_push_tx/11-nsequence.md). Agents can also search and read this documentation through its [MCP server](https://hub.bsvblockchain.org/~gitbook/mcp).

# 11 - nSequence

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.

<figure><img src="https://3421145409-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRTEKu4E7Fvtss3GI9CYU%2Fuploads%2Fgit-blob-864ae4491b49c56eda0df7f69637cd647c1207f0%2FBSVA-BitcoinScript_Chapter5-Animation10.gif?alt=media" alt=""><figcaption></figcaption></figure>

#### Example: Extract and check nSequence

In this example, we will extract the nSequence value of this input and only allow the UTXO to be spent if it is final.

<table><thead><tr><th width="237.33333333333331">Stack</th><th>Script</th><th>Description</th></tr></thead><tbody><tr><td>&#x3C;r_tx_preimg></td><td>...</td><td>Version, hash_prevouts, hash_nSequence, hash_outpoints, script and value have been removed</td></tr><tr><td>&#x3C;r_tx_preimg></td><td>OP_4</td><td>nSequence length is 4 bytes long</td></tr><tr><td>&#x3C;r_tx_preimg> 0x04</td><td>OP_SPLIT</td><td>Split nSequence</td></tr><tr><td>&#x3C;nsequence> &#x3C;rr_tx_preimg></td><td>OP_SWAP</td><td>Move to top of stack</td></tr><tr><td>&#x3C;rr_tx_preimg> &#x3C;nsequence></td><td>0xFFFFFFFF</td><td>0xFFFFFFFF is final</td></tr><tr><td>&#x3C;rr_tx_preimg> &#x3C;nsequence> 0xFFFFFFFF</td><td>OP_EQUALVERIFY</td><td>Fail script if tx is non-final</td></tr><tr><td>&#x3C;r_tx_preimg></td><td>...</td><td>rest of script</td></tr></tbody></table>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://hub.bsvblockchain.org/higher-learning/bsv-academy/introduction-to-bitcoin-script/chapter-5-op_push_tx/11-nsequence.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
