> 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/07-hashsequence.md). Agents can also search and read this documentation through its [MCP server](https://hub.bsvblockchain.org/~gitbook/mcp).

# 07 - hashSequence

The hashSequence field is the hash of the concatenation of the nSequence values of all inputs being signed. The make-up of the Hash of nSequence is dependent on whether `SIGHASH_ANYONECANPAY` flag is used.

If `SIGHASH_ANYONECANPAY` is **NOT** used, the hash value is a SHA256 hash of a concatenated list of the sequence number of each of the transaction's inputs.

If `SIGHASH_ANYONECANPAY` is used, the value is a 32 byte null string.

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

#### Example: Check all sequence values are final

In this example, the script checks that two inputs are used, and that the input is final. To perform the check, the hash of sequence will be split from `r_tx_preimg` and tested against a hash of the expected value.

It is assumed that `version` and `hash_prevouts` have both been removed from `r_tx_preimage`.

<table><thead><tr><th width="250.33333333333331">Stack</th><th width="187">Script</th><th>Description</th></tr></thead><tbody><tr><td>&#x3C;r_tx_preimg></td><td>...</td><td>nVersion field and hashPrevouts have been removed</td></tr><tr><td>&#x3C;r_tx_preimg></td><td>0x20</td><td>add hash_nSequence length to the stack</td></tr><tr><td>&#x3C;r_tx_preimg> 0x20</td><td>OP_SPLIT</td><td>Split hash_nSequence from pre-image</td></tr><tr><td>&#x3C;hash_nSequence> &#x3C;rr_tx_preimg></td><td>OP_SWAP</td><td>Swap hash_nSequence to front</td></tr><tr><td>&#x3C;rr_tx_preimg> &#x3C;hash_nSequence></td><td>0xffffffffffffffff</td><td>Expected sequence value if two final inputs are used</td></tr><tr><td>&#x3C;rr_tx_preimg> &#x3C;hash_nSequence> 0xffffffffffffffff</td><td>OP_SHA256</td><td>Hash sequence value</td></tr><tr><td>&#x3C;rr_tx_preimg> &#x3C;hash_nSequence> &#x3C;sha256_ffffffff></td><td>OP_EQUALVERIFY</td><td>Check it is equal - fail if not</td></tr><tr><td>&#x3C;rr_tx_preimg></td><td>...</td><td>rest of script</td></tr></tbody></table>

This gives us a useful tool for managing closure of payment channels, providing an optimal processing path for channels submitted with fully final inputs.


---

# 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/07-hashsequence.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.
