Error codes
Every failed request call rejects with an error object:
interface ProviderRpcError extends Error {
code: number;
message: string;
data?: unknown;
}
Handle the codes you can recover from, starting with the most common one — the user saying no:
try {
await provider.request({ method: 'eth_requestAccounts' });
} catch (error) {
switch (error.code) {
case 4001:
// User rejected — normal flow, don't show an error state.
break;
case -32002:
// A request is already pending — point the user at the wallet
// instead of firing the request again.
break;
default:
console.error(error);
}
}
Provider errors (EIP-1193)
| Code | Name | What it means for your dapp |
|---|---|---|
| 4001 | User rejected request | The user dismissed the approval. Expected behaviour — never retry automatically. |
| 4100 | Unauthorized | The account or method has not been authorised. Connect first with eth_requestAccounts. |
| 4200 | Unsupported method | Core does not implement the method — for example eth_sign, which is rejected by design. |
| 4900 | Disconnected | The provider cannot serve any request. Listen for connect before retrying. |
| 4901 | Chain disconnected | Connected, but not to the chain the request targets. |
JSON-RPC errors (EIP-1474)
| Code | Name | Typical cause |
|---|---|---|
| -32700 | Parse error | Malformed request payload |
| -32600 | Invalid request | Request object missing required fields |
| -32601 | Method not found | Typo in the method name, or a method the network's node does not expose |
| -32602 | Invalid params | Wrong parameter count, type, or encoding |
| -32603 | Internal error | The node failed to process an otherwise valid request |
| -32000 | Invalid input / server error | Catch-all from the RPC node — inspect message |
| -32002 | Resource unavailable / request pending | An approval window for the same request is already open |
Practical rules
- 4001 is not an error state. Users decline requests all the time; treat it as a cancelled action.
- Don't queue duplicate prompts. If you receive -32002, the approval window is already open.
- Log
error.data. Contract reverts frometh_callandeth_estimateGasusually carry the revert reason there.