Error codes
Every CrackPay request that fails rejects with an error that has a numeric
code. Match on the code, never on the message: messages may change.
| Code | ErrorCode. | Meaning | Tell the user |
|---|---|---|---|
4001 | UserRejected | Cancelled the confirmation or the passkey prompt | "Cancelled." Let them retry. |
4100 | Unauthorized | Not allowed for this app: a contract outside its listing, or a forbidden token call | Generic failure. It is a bug or a missing listing entry. |
4200 | UnsupportedMethod | The method is not supported | Do not call it. See Provider methods. |
4902 | UnrecognizedChain | Asked for a chain other than Arc | Do not switch chains. |
-32602 | InvalidParams | Malformed request | Fix the request. |
-32603 | Internal | Reverted, never confirmed, or a failure inside CrackPay | "The payment didn't go through." |
Handling errors
import { ErrorCode, errorCode, isUserRejection } from "@crackpay/miniapp-sdk";
try {
await walletClient.writeContract(request);
} catch (error) {
if (isUserRejection(error)) return show("Cancelled.");
if (errorCode(error) === ErrorCode.Unauthorized) {
console.error("This call is not allowed for the app; check its listing", error);
}
console.error(error);
show("The payment didn't go through. Please try again.");
}
errorCode reads the code whether the error came from the provider or was wrapped
by viem or wagmi.
A payment that may or may not have happened
A -32603 whose message says the operation "was submitted but never
confirmed" is special: the payment may have gone through. Tell the user to check
their balance before trying again, and never retry automatically.