> For the complete documentation index, see [llms.txt](https://docs.stacks.co/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.stacks.co/reference/api/stacks-blockchain-api/nonce-handling.md).

# Nonce Handling

Learn how to handle nonces on Stacks.

In order to prevent "stuck" transactions, you must track the next available nonce for principals issuing transactions. The Stacks Blockchain API provides an endpoint to make nonce handling simpler when using the following command:

```bash
curl 'https://api.hiro.so/extended/v1/address/SP3XXK8BG5X7CRH7W07RRJK3JZJXJ799WX3Y0SMCR/nonces'
```

```json
{
  "last_executed_tx_nonce": 2789412,
  "last_mempool_tx_nonce": 2789413,
  "possible_next_nonce": 2789414,
  "detected_missing_nonces": []
}
```

The `possible_next_nonce` property is the nonce suggested for a given principal's next transaction. It is derived as the next integer to the largest nonce found in blocks and mempool. It does not take into account missing nonces.

The `detected_missing_nonces` property finds any non-contiguous nonces after inspecting transactions from blocks and the mempool. For example, for a given principal, if the latest transaction included in a block has a nonce of 5, and there's only one transaction in the mempool with nonce 7, then it indicates that something likely went wrong with transaction with nonce 6 (either it was not created or broadcasted correctly by a client, or it was dropped for whatever reason). This is a strong indication that the mempool transaction with nonce 7 will never be mined since the previous nonce is missing.

Clients that continue to broadcast transactions with the `possible_next_nonce` property of 8, then 9, then 10, will likely result in all of their pending/mempool transactions never going through. For all transactions to go through, clients should first use any missing nonces before using the suggested `possible_next_nonce`.


---

# 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://docs.stacks.co/reference/api/stacks-blockchain-api/nonce-handling.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.
