Description: User doesn’t have enough tokens for the transactionSolution: Request user to add funds to their wallet or choose a different payment tokenExample:
Copy
Ask AI
if (error.message === "INSUFFICIENT_BALANCE") { toast.error("Insufficient balance. Please add funds to your wallet."); // Optionally redirect to fiat onramp openFiatOnramp();}
INVALID_TOKEN_ADDRESS
Description: Token contract not supported on the target chainSolution: Verify token is supported and provide alternative optionsExample:
Copy
Ask AI
if (error.message === "INVALID_TOKEN_ADDRESS") { toast.error("This token is not supported. Please choose another."); showSupportedTokens();}
MINIMUM_AMOUNT_NOT_MET
Description: Transaction amount is below the minimum thresholdSolution: Increase transaction amount or inform user of minimum requirementsExample:
Copy
Ask AI
if (error.message === "MINIMUM_AMOUNT_NOT_MET") { toast.error(`Minimum amount is $${minimumAmount}. Please increase your amount.`);}
MAXIMUM_AMOUNT_EXCEEDED
Description: Transaction amount exceeds maximum limitSolution: Reduce amount or split into multiple transactionsExample:
Copy
Ask AI
if (error.message === "MAXIMUM_AMOUNT_EXCEEDED") { toast.error(`Maximum amount is $${maximumAmount}. Please reduce your amount.`);}
Description: Price moved beyond acceptable tolerance during executionSolution: Retry with higher slippage tolerance or wait for price stabilityExample:
Copy
Ask AI
if (error.message === "SLIPPAGE") { toast.warning("Price moved unfavorably. Retrying with adjusted settings..."); retryWithHigherSlippage();}
NETWORK_ERROR
Description: RPC connection issues or blockchain congestionSolution: Retry after delay or switch to alternative RPCExample:
Copy
Ask AI
if (error.message === "NETWORK_ERROR") { toast.error("Network issue detected. Please check connection and try again."); scheduleRetry();}
QUOTE_EXPIRED
Description: Price quote is no longer validSolution: Get fresh quote and retry transactionExample:
Description: Gas limit set too low for transactionSolution: Increase gas limit or suggest gas optimizationExample:
Copy
Ask AI
if (error.message === "INSUFFICIENT_GAS") { toast.error("Transaction requires more gas. Increasing gas limit..."); retryWithHigherGas();}
NONCE_TOO_LOW
Description: Transaction nonce conflictSolution: Wait for pending transactions to completeExample:
Copy
Ask AI
if (error.message === "NONCE_TOO_LOW") { toast.info("Please wait for pending transactions to complete."); waitAndRetry();}
TRANSACTION_REVERTED
Description: Contract reverted the transactionSolution: Check contract state and parametersExample:
Copy
Ask AI
if (error.message === "TRANSACTION_REVERTED") { toast.error("Transaction was rejected by the contract. Please check requirements."); showTransactionDetails();}
function getErrorMessage(error: Error): { title: string; message: string; action?: string } { switch (error.message) { case "INSUFFICIENT_BALANCE": return { title: "Insufficient Balance", message: "You don't have enough funds for this transaction.", action: "Add funds to your wallet or choose a different payment method.", }; case "SLIPPAGE": return { title: "Price Changed", message: "The price moved while processing your transaction.", action: "We'll retry automatically with updated pricing.", }; case "NETWORK_ERROR": return { title: "Connection Issue", message: "Unable to connect to the blockchain network.", action: "Please check your internet connection and try again.", }; case "QUOTE_EXPIRED": return { title: "Quote Expired", message: "The price quote is no longer valid.", action: "Getting a fresh quote automatically...", }; default: return { title: "Transaction Failed", message: "An unexpected error occurred.", action: "Please try again or contact support if the problem persists.", }; }}// Usage in componentfunction ErrorDisplay({ error }: { error: Error }) { const errorInfo = getErrorMessage(error); return ( <div className="error-display"> <h3>{errorInfo.title}</h3> <p>{errorInfo.message}</p> {errorInfo.action && <p className="error-action">{errorInfo.action}</p>} </div> );}
Keep users informed about what’s happening, especially during longer operations like cross-chain transactions.
Copy
Ask AI
// Good: Clear status messages<div className="status"> <Spinner /> <p>Processing your payment... This may take 2-3 minutes.</p></div>// Bad: No feedback during long operations<div>{isLoading && <Spinner />}</div>
Implement Retry Logic
Many errors are transient and can be resolved by retrying the operation.
When reporting issues, please include: - Error messages and codes - Steps to reproduce the issue - Browser and device
information - Network conditions (if relevant) - Order IDs (if applicable)
Remember: Good error handling is about more than just catching errors—it’s about providing a smooth, understandable experience for your users even when things go wrong.