# Troubleshooting

> Fixes for common problems with LocalNet, networks, opt-ins, balances, prices and payments.

Find your error message or symptom in the table, apply the fix, and follow the link if you need the background.

## Quick diagnosis

| Symptom | Likely cause | Fix |
|---|---|---|
| `Connection refused` on port 4001, or `MaxRetryError ... port=4001` | LocalNet is not running | `algokit localnet start` |
| `invalid_exact_avm_payload_genesis_hash_mismatch` | Client and server use different networks, or LocalNet was reset under a running server | Use the same network on both sides; restart servers after `algokit localnet reset` |
| `NetworkMismatchError: algod is on ... but the payment is for ...` | The client's algod is on another network than the offer | Point the client at an algod on the offer's network |
| `transaction_simulation_failed` mentioning an asset | An account has not opted in to the ASA | Opt in both `pay_to` and the buyer |
| `transaction_simulation_failed` mentioning balance, or `below min` | An account would drop below its minimum balance | Add ALGO: 0.1 ALGO base plus 0.1 ALGO per opted-in asset |
| `ConfigurationError: price ... does not cover facilitator fees` | ALGO price in `(0, 2000]` | Raise the price above 2,000 microALGO or pass `allow_loss=True` |
| `NoMatchingRequirementsError`, or `PaymentError: Failed to handle payment: ...` from the httpx client, or `SpendLimitExceededError` from `paid_mcp_session` (0.5.1; an `ExceptionGroup` in 0.5.0) | The price is above the spend cap, the asset is not allowed, or the offer is for another network | Check the offer; adjust `spend_controls` deliberately |
| `SpendLimitExceededError` / `PaymentNotAllowedError` in x402-avm-js | The offer is above `maxAmount` (1,000,000 base units by default) or not on an allow list | Check the offer; raise `maxAmount` deliberately |
| `FutureWarning: PaymentGate.wrap() was called without transport=` | `wrap(mcp)` without `transport=` serves legacy SSE | Pass `transport="streamable-http"` (recommended) or `transport="sse"` |
| `PaymentRequiredError: payment required: tool ... must be called through the payment gate` | A priced tool was reached without passing through the gate, for example over a transport the gate does not wrap | Serve the app built by `gate.wrap(...)`, or install both `gate.middleware()` and `SettleOnSuccessMiddleware` |
| HTTP `500` with `payment gate misconfigured` | The app was built without `SettleOnSuccessMiddleware` | Use `gate.wrap(...)` or `mcp.add_middleware(SettleOnSuccessMiddleware(gate))` |
| The MCP client cannot connect, or gets `404` / `405` | Client and server use different transports | Use `.../mcp` for `transport="streamable-http"` and `.../sse` for `transport="sse"` |
| `SettlementError: payment settlement failed: ...` | Submission failed: expired rounds, fee payer out of ALGO, node error | Check the fee payer's balance and algod; the buyer was not charged |
| `402` with `Replay detected`, or `transaction_simulation_failed` on a resent payment | The same signed payment was sent twice | Build a new payment for each call |
| `invalid_exact_avm_payload_recipient_mismatch` | The payment goes to another address than `payTo` | Use the `payTo` from the challenge |
| `invalid_exact_avm_payload_invalid_signature` | Wrong key, or the transaction changed after signing | Sign with the sender's key after the group id is set |

All facilitator codes are explained on [Error codes](https://x402-avm.github.io/reference/errors).

## LocalNet not reachable

```text
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=4001): Max retries exceeded with url: /v2/status
```

1. Start LocalNet: `algokit localnet start`.
2. Check algod:

```bash
curl -H "X-Algo-API-Token: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" http://localhost:4001/v2/status
```

3. Check the endpoints and tokens: algod `http://localhost:4001` and KMD `http://localhost:4002` use 64 × `a`; the indexer at `http://localhost:8980` needs no token.

## Asset not opted in

An account must opt in to an ASA, such as USDC, before it can receive it, and both the vendor's `pay_to` account and the buyer need it. The opt-in code is in [Accept USDC](https://x402-avm.github.io/production/mainnet#accept-usdc).

## Balance below the minimum

Every account must keep 100,000 microALGO (0.1 ALGO), plus 100,000 microALGO for each asset it has opted in to (applications add more). An account cannot spend below this, so a payment that would cross it fails simulation. Top the account up with ALGO.

## The client keeps getting 402 after paying

The server rejected the payment and answered with the challenge again. Look at the server's logs, or decode the response, for the failure reason. Common causes:

- The transactions expired (their last valid round passed) between building and sending.
- The group was modified after signing, so the group id or signature no longer matches.
- The buyer cannot cover the amount.
- The client is on a different network from the server.

The official `x402` httpx client does not loop: after a bounded number of paid retries it returns the server's answer, so a `402` after paying reaches your code.

## Prices below the fee floor

```text
ai_economy_sdk.exceptions.ConfigurationError: price 1000 for tool 'summarize' does not cover facilitator fees (2000 microalgos); raise it or pass allow_loss=True
```

Charge more than 2,000 microALGO, or pass `allow_loss=True` to subsidize calls on purpose. See [the fee floor](https://x402-avm.github.io/build/pricing#the-fee-floor).

## LocalNet was reset

A reset creates a new genesis hash, so the LocalNet network id changes. Restart servers and clients so they read the new id; see [LocalNet](https://x402-avm.github.io/production/networks#localnet).

## Still stuck

Search the [examples](https://github.com/x402-avm/examples) for a working configuration close to yours, and open an issue in the relevant repository with the error, the package versions and the network.

Source: https://x402-avm.github.io/resources/troubleshooting
