> For the complete documentation index, see [llms.txt](https://docs.surged.fun/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.surged.fun/integration/sdk/errors.md).

# Handling errors

Contracts revert with a typed error, which reaches you as an unreadable hex selector. `explainError` turns anything thrown by viem, a wallet or this package into a stable code and a sentence you can show.

```ts
import { explainError } from '@surged/sdk'

try {
  await wallet.sendTransaction({ to: launch.curve, ...call })
} catch (error) {
  const { code, message } = explainError(error)
  // code: 'SlippageExceeded'
  // message: 'The price moved past your slippage tolerance. Adjust it and try again.'
}
```

**Branch on `code`, show `message`.** The code is the contract's own error name and is stable; the wording is not, and may improve between versions. The message never echoes calldata, addresses or long hex blobs.

## The codes you will actually hit

| Code                    | What happened                                                          | What to do                                                                  |
| ----------------------- | ---------------------------------------------------------------------- | --------------------------------------------------------------------------- |
| `SlippageExceeded`      | The price moved between your quote and the block your trade landed in. | Requote. During a launch, widen the tolerance or wait out the snipe window. |
| `CurveGraduated`        | The token left the curve; it trades on Uniswap now.                    | Refresh the launch and follow `graduation.pool`.                            |
| `ZeroAmount`            | The amount was zero.                                                   |                                                                             |
| `USER_REJECTED`         | The person dismissed the wallet prompt.                                | Not an error worth reporting.                                               |
| `LaunchesPaused`        | New launches are paused.                                               | Only on the launch path.                                                    |
| `EconomicsMismatch`     | The launch terms changed while you were building the transaction.      | Re-read `GET /config` and rebuild.                                          |
| `InvalidBuyerSignature` | A bundle wallet did not sign this launch.                              | Collect the consents again.                                                 |
| `InvalidBuyerNonce`     | A buyer nonce was consumed or changed.                                 | Review the launch and collect fresh consents.                               |
| `SignatureExpired`      | A bundle consent passed its deadline.                                  | Sign again.                                                                 |

The full list is in the package's `MESSAGES` table.

## Decoding revert data yourself

If you have the raw bytes, for instance from a simulation, `decodeLaunchpadError` names them:

```ts
import { decodeLaunchpadError } from '@surged/sdk'

decodeLaunchpadError('0x...') // { errorName: 'SlippageExceeded', args: [...] }
```

## A mined transaction is not a successful one

A revert produces a receipt like any other. Always check it:

```ts
const receipt = await publicClient.waitForTransactionReceipt({ hash })
if (receipt.status !== 'success') {
  // The contract rejected it. Re-read the launch before retrying.
}
```


---

# 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 dynamically by asking a question.

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

```
GET https://docs.surged.fun/integration/sdk/errors.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
