# Nonce

Transactions signed by the same private key (i.e., with the same address) are submitted and handled in an order using nonce. Usually, nonce is a non-negative integer value, starting from 0, that stands for the number of transactions accepted to blocks so far. Whenever a transaction is submitted its nonce is check in the following way:

* If the nonce value is equal to (the number of transactions with the same address in blocks) + 1, it's accepted
* Otherwise, it's kept in pending mode with a predefined timeout value until the condition met.

We call this type of nonce *numbered nonce*. This is enough for typical human-generated transactions. For more use cases like machine-generated transactions, we support two more types: *ordered nonce* and *unordered nonce*.

Transactions with loosely ordered nonce are ordered using timestamp:

* If the timestamp is larger than the last timestamp, it's accepted
* Otherwise, it' rejected

Transactions with unordered nonce is always accepted unless a transaction with the same transaction hash is already in blocks.

Three different types of nonce can be compared as follows:

| Type      | Nonce Field          | When To Use                                                               | Good For                                                                 | API Version |
| --------- | -------------------- | ------------------------------------------------------------------------- | ------------------------------------------------------------------------ | ----------- |
| Numbered  | Non-negative integer | Single client                                                             | Human-generated txs                                                      | 1.0         |
| Unordered | -1                   | Single or multiple clients, transactions are not aligned with each other. | Machine-generated txs with different generation time and submission time | 1.0         |
| Ordered   | -2                   | Multiple clients, transactions are aligned with time                      | Machine-generated txs with multiple clients                              | 1.0         |


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.ainetwork.ai/ain-blockchain/ai-network-design/transactions/nonce.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
