# Get Transaction Nonce

Get the next pending transaction nonce of an EVM address — used when building a transaction requested by a dApp.

## Overview

The server calls `eth_getTransactionCount(address, "pending")` on the RPC node configured for `chainSlug` and returns the result as a decimal integer. This is an on-chain account nonce, not a sign-in nonce.

- **With `address`:** the address is used directly. It is not checked against the caller's wallets.
- **Without `address`:** the server uses the caller's *earliest-created* mainnet wallet whose `chain` equals `chainSlug`, and returns `404` if there is none. The OpenAPI description calls this the primary wallet, but the implementation does not look at the primary flag — pass `address` to be explicit.
- `chainSlug` must be a chain registered with an RPC URL (for example `gnosis`); otherwise the call returns `400`.
- Rate limit: 30 requests per minute.

## Endpoint

### `GET /v1/dapps/nonce`

Authentication: bearer token required.

Returns the pending nonce (eth_getTransactionCount, 'pending') for an EVM address on the given chain.

**Query parameters**

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `chainSlug` | string | yes | Chain identifier, e.g. `gnosis`. |
| `address` | string | no | EVM address (`0x` + 40 hex characters). If omitted, the caller's earliest-created mainnet wallet on `chainSlug` is used. |

**Responses**

`200` OK

```json
{ "nonce": 42 }
```

`400` No RPC

```json
{
  "error": "NO_RPC_URL",
  "message": "No RPC URL configured for chain 'unknownchain'"
}
```

`404` No Wallet

```json
{
  "error": "WALLET_NOT_FOUND",
  "message": "No wallet found for chain 'gnosis'"
}
```

`422` RPC Error

```json
{
  "error": "RPC_ERROR",
  "code": -32000,
  "message": "error message returned by the RPC node"
}
```

**Example request**

```bash
curl "https://api.aureahub.com/v1/dapps/nonce?chainSlug=gnosis&address=0x71C7656EC7ab88b098defB751B7401B5f6d8976F" \
  -H "Authorization: Bearer YOUR_TOKEN"
```

If the RPC node does not answer within 15 seconds the call returns `504` with `{ "error": "RPC_TIMEOUT", "message": "The RPC node did not respond in time" }`. On `422`, `code` and `message` are the JSON-RPC error returned by the node.

## Implementation

```javascript
async function getPendingNonce(token, chainSlug, address) {
  const params = new URLSearchParams({ chainSlug, address });
  const res = await fetch(`https://api.aureahub.com/v1/dapps/nonce?${params}`, {
    headers: { Authorization: `Bearer ${token}` }
  });
  if (!res.ok) throw new Error((await res.json()).message);
  const { nonce } = await res.json();
  return nonce; // decimal integer
}
```

---

Web version: https://docs.aureahub.com/#dapps-nonce
