Errors
The StarKey Ethereum provider follows the standard EIP-1193 provider error codes, plus standard JSON-RPC error codes for malformed or unsupported requests.
Provider error codes
| Code | Name | Meaning |
|---|---|---|
4001 | User Rejected Request | User declined the connection, transaction, or sign prompt. |
4100 | Unauthorized | Requested method/account hasn’t been authorized by the user. |
4200 | Unsupported Method | Provider doesn’t support the requested method. |
4900 | Disconnected | Provider is disconnected from all chains. |
4901 | Chain Disconnected | Provider is disconnected from the specifically requested chain. |
4902 | Unrecognized Chain | Target chain hasn’t been added via wallet_addEthereumChain. |
JSON-RPC error codes
| Code | Meaning |
|---|---|
-32700 | Parse error — invalid JSON was sent. |
-32600 | Invalid request. |
-32601 | Method not found. |
-32602 | Invalid params — e.g. a malformed transaction object. |
-32603 | Internal error. |
Rejection shape
Rejections throw an error object, most commonly in the form:
{ code: 4001, message: 'User rejected the request.' }try {
const accounts = await provider.request({ method: 'eth_requestAccounts' })
} catch (err: any) {
if (err.code === 4001) {
// user explicitly rejected — show a non-blocking message
}
}On-chain failure vs. rejection
A transaction can also fail after being accepted and mined — this is not a JavaScript exception. Check the status field on the transaction receipt ('0x1' success, '0x0' reverted) — see Sending a Transaction. A resolved eth_sendTransaction call only means the transaction was submitted, not that it succeeded.
Recommended handling
async function connectWallet() {
try {
const accounts = await provider.request({ method: 'eth_requestAccounts' })
if (accounts.length === 0) {
// no accounts available
return
}
// proceed with accounts[0]
} catch (err: any) {
if (err.code === 4001) {
// user rejected — don't retry automatically
}
}
}async function switchToChain(chainId: string) {
try {
await provider.request({ method: 'wallet_switchEthereumChain', params: [{ chainId }] })
} catch (err: any) {
if (err.code === 4902) {
// chain unrecognized — call wallet_addEthereumChain first, then retry the switch
}
}
}Notes
- Don’t retry a rejected prompt-based call (
eth_requestAccounts,eth_sendTransaction,personal_sign, etc.) automatically in a loop — the rejection is a deliberate user action. eth_accountsresolves to[]rather than rejecting when there’s no active connection — check the array length rather than expecting a thrown error.
Related pages
Last updated on