Provides production UX patterns for dApp frontends: wallet connection flows (RainbowKit, multi-state), four-state transaction lifecycle, error handling taxonomy (4001 rejection, revert decoding), gas estimation with USD display, network switching, approval patterns (infinite vs exact, Permit2), mobile wallet support (WalletConnect v2, EIP-6963)…
Ships in frontend-ux. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Production UX patterns for dApp frontends. Covers the full user journey from wallet connection through transaction confirmation, with error handling, gas estimation, approval flows, mobile support, and a production QA checklist. Built on wagmi v2, viem, and RainbowKit.
Most dApp frontends ship with broken UX because developers treat wallet connection as a button click and transactions as a loading spinner. Both are state machines with multiple failure modes that users encounter constantly.
disconnected, connecting, connected, and wrong-network. Showing a single "Connect Wallet" button that flips to "Connected" misses the connecting spinner (important on mobile where WalletConnect takes seconds), the wrong-network prompt (users will be on mainnet when your dApp is on Base), and auto-reconnection on page reload (flash of disconnected state).idle, awaiting-signature (wallet popup open), pending (tx submitted, waiting for block inclusion), and confirmed-or-failed. Each state needs distinct UI. Users sitting at "Loading..." don't know if they need to open their wallet, wait for the chain, or if something failed.type(uint256).max approval is convenient but means a compromised spender contract can drain all tokens forever. Offer exact-amount approval as the default with infinite as an opt-in, or use Permit2 for single-transaction approve-and-transfer.etherscan.io breaks on L2s. Use the chain's configured blockExplorers from wagmi to construct the correct URL. disconnected
|
| user clicks "Connect"
v
connecting ----(user cancels)---> disconnected
|
| wallet responds
v
connected ----(wrong chain detected)---> wrong-network
| |
| correct chain | user switches chain
v v
ready (can transact) <------------------------+
RainbowKit provides a production-ready wallet connection modal with built-in support for 30+ wallets, chain switching, ENS resolution, and responsive design.
npm install @rainbow-me/rainbowkit wagmi viem @tanstack/react-query
// config.ts
import { getDefaultConfig } from "@rainbow-me/rainbowkit";
import { mainnet, arbitrum, base, optimism, polygon } from "wagmi/chains";
export const config = getDefaultConfig({
appName: "My dApp",
projectId: process.env.NEXT_PUBLIC_WC_PROJECT_ID!,
chains: [mainnet, arbitrum, base, optimism, polygon],
ssr: true,
});
// providers.tsx
"use client";
import { RainbowKitProvider, darkTheme } from "@rainbow-me/rainbowkit";
import { WagmiProvider } from "wagmi";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { config } from "./config";
import { useState, type ReactNode } from "react";
import "@rainbow-me/rainbowkit/styles.css";
export function Providers({ children }: { children: ReactNode }) {
const [queryClient] = useState(() => new QueryClient());
return (
<WagmiProvider config={config}>
<QueryClientProvider client={queryClient}>
<RainbowKitProvider theme={darkTheme()}>
{children}
</RainbowKitProvider>
</QueryClientProvider>
</WagmiProvider>
);
}
RainbowKit's ConnectButton.Custom exposes all connection states for full control.
import { ConnectButton } from "@rainbow-me/rainbowkit";
function WalletButton() {
return (
<ConnectButton.Custom>
{({
account,
chain,
openAccountModal,
openChainModal,
openConnectModal,
mounted,
}) => {
const connected = mounted && account && chain;
if (!mounted) {
return <button disabled aria-hidden>Connect Wallet</button>;
}
if (!connected) {
return (
<button onClick={openConnectModal} type="button">
Connect Wallet
</button>
);
}
if (chain.unsupported) {
return (
<button onClick={openChainModal} type="button">
Wrong Network
</button>
);
}
return (
<div style={{ display: "flex", gap: 8 }}>
<button onClick={openChainModal} type="button">
{chain.name}
</button>
<button onClick={openAccountModal} type="button">
{account.displayName}
</button>
</div>
);
}}
</ConnectButton.Custom>
);
}
Modern wallets announce themselves via EIP-6963 instead of fighting over window.ethereum. wagmi v2 discovers these automatically when multiInjectedProviderDiscovery is true (default).
import { useConnect } from "wagmi";
function WalletList() {
const { connectors, connect, isPending } = useConnect();
return (
<ul role="list" aria-label="Available wallets">
{connectors.map((connector) => (
<li key={connector.uid}>
<button
onClick={() => connect({ connector })}
disabled={isPending}
aria-busy={isPending}
>
{connector.icon && (
<img
src={connector.icon}
alt=""
width={24}
height={24}
/>
)}
{connector.name}
</button>
</li>
))}
</ul>
);
}
Every transaction passes through four states. Each needs distinct UI.
idle
|
| user clicks action button
v
awaiting-signature ----(user rejects: 4001)---> idle (silent reset)
|
| wallet signs and broadcasts
v
pending ----(tx dropped/timeout)---> failed
|
| block inclusion
v
confirmed ----(receipt.status === "reverted")---> failed
"use client";
import {
useWriteContract,
useWaitForTransactionReceipt,
useChainId,
} from "wagmi";
import { parseUnits } from "viem";
import { BaseError, UserRejectedRequestError } from "viem";
const erc20Abi = [
{
name: "transfer",
type: "function",
stateMutability: "nonpayable",
inputs: [
{ name: "to", type: "address" },
{ name: "amount", type: "uint256" },
],
outputs: [{ name: "", type: "bool" }],
},
] as const;
type TxState = "idle" | "awaiting-signature" | "pending" | "confirmed" | "failed";
function getExplorerUrl(chainId: number, hash: string): string {
const explorers: Record<number, string> = {
1: "https://etherscan.io",
10: "https://optimistic.etherscan.io",
137: "https://polygonscan.com",
8453: "https://basescan.org",
42161: "https://arbiscan.io",
};
const base = explorers[chainId] ?? "https://etherscan.io";
return `${base}/tx/${hash}`;
}
function TransferToken({
token,
decimals,
to,
amount,
}: {
token: `0x${string}`;
decimals: number;
to: `0x${string}`;
amount: string;
}) {
const chainId = useChainId();
const {
writeContract,
data: hash,
isPending: isSigning,
error: writeError,
reset,
} = useWriteContract();
const {
isLoading: isConfirming,
isSuccess,
data: receipt,
error: receiptError,
} = useWaitForTransactionReceipt({ hash });
function getTxState(): TxState {
if (isSigning) return "awaiting-signature";
if (isConfirming) return "pending";
if (isSuccess && receipt?.status === "success") return "confirmed";
if (receipt?.status === "reverted" || writeError || receiptError) return "failed";
return "idle";
}
const txState = getTxState();
function isUserRejection(error: Error): boolean {
if (error instanceof UserRejectedRequestError) return true;
const msg = error.message.toLowerCase();
return msg.includes("user rejected") || msg.includes("user denied");
}
function handleSubmit() {
writeContract({
address: token,
abi: erc20Abi,
functionName: "transfer",
args: [to, parseUnits(amount, decimals)],
});
}
// 4001 user rejection: silently reset, no error toast
if (writeError && isUserRejection(writeError)) {
reset();
return null;
}
const buttonLabels: Record<TxState, string> = {
idle: "Transfer",
"awaiting-signature": "Confirm in wallet...",
pending: "Waiting for confirmation...",
confirmed: "Transfer complete",
failed: "Transaction failed",
};
return (
<div>
<button
onClick={handleSubmit}
disabled={txState !== "idle" && txState !== "failed"}
aria-busy={txState === "awaiting-signature" || txState === "pending"}
>
{buttonLabels[txState]}
</button>
{txState === "pending" && hash && (
<p>
Tx submitted.{" "}
<a
href={getExplorerUrl(chainId, hash)}
target="_blank"
rel="noopener noreferrer"
>
View on explorer
</a>
</p>
)}
{txState === "confirmed" && hash && (
<div>
<p>
Confirmed in block {receipt?.blockNumber.toString()}.{" "}
<a
href={getExplorerUrl(chainId, hash)}
target="_blank"
rel="noopener noreferrer"
>
View on explorer
</a>
</p>
<button onClick={() => reset()}>Send another</button>
</div>
)}
{txState === "failed" && writeError && !isUserRejection(writeError) && (
<div role="alert">
<p>
{writeError instanceof BaseError
? writeError.shortMessage
: writeError.message}
</p>
<button onClick={() => reset()}>Try again</button>
</div>
)}
{txState === "failed" && receipt?.status === "reverted" && (
<div role="alert">
<p>Transaction reverted on-chain.</p>
<button onClick={() => reset()}>Try again</button>
</div>
)}
</div>
);
}
Not all errors deserve the same UX treatment. Categorize by source and severity.
| Code | Name | Source | UX Response |
|---|---|---|---|
| 4001 | User Rejected Request | Wallet | Silent reset to idle. Do NOT show an error. |
| 4100 | Unauthorized | Wallet | Prompt reconnection. Wallet may have locked. |
| 4200 | Unsupported Method | Wallet | Fallback to alternative method or show upgrade prompt. |
| 4900 | Disconnected | Wallet | Show reconnect button. |
| 4901 | Chain Disconnected | Wallet | Prompt chain switch. |
| -32700 | Parse Error | RPC | Internal error. Log to monitoring, show generic message. |
| -32600 | Invalid Request | RPC | Internal error. Log to monitoring, show generic message. |
| -32601 | Method Not Found | RPC | RPC does not support this call. Try alternative RPC. |
| -32602 | Invalid Params | RPC | Bug in your code. Fix the parameters. |
| -32603 | Internal Error | RPC | Often means insufficient funds. Parse inner message. |
import {
BaseError,
ContractFunctionRevertedError,
UserRejectedRequestError,
InsufficientFundsError,
} from "viem";
function parseTransactionError(error: Error): {
message: string;
shouldToast: boolean;
} {
if (error instanceof UserRejectedRequestError) {
return { message: "Transaction cancelled", shouldToast: false };
}
if (error instanceof BaseError) {
if (error.walk((e) => e instanceof InsufficientFundsError)) {
return { message: "Insufficient funds for gas + value", shouldToast: true };
}
const revert = error.walk(
(e) => e instanceof ContractFunctionRevertedError
);
if (revert instanceof ContractFunctionRevertedError) {
const reason = revert.data?.errorName ?? revert.reason ?? "Unknown revert";
return { message: `Contract error: ${reason}`, shouldToast: true };
}
return { message: error.shortMessage, shouldToast: true };
}
return { message: error.message, shouldToast: true };
}
See resources/error-codes.md for the complete error code table with detection patterns.
| Error Type | Display Method | Reason |
|---|---|---|
| User rejection | None (silent reset) | User chose to cancel |
| Insufficient funds | Inline, near balance display | User needs to see their balance |
| Contract revert | Inline, near action button | Contextual to the failed action |
| Network error | Toast | Global issue, not action-specific |
| RPC rate limit | Toast with retry | Transient, affects all operations |
Users should see transaction cost in their local currency, not in gwei.
import { useEstimateGas, useGasPrice } from "wagmi";
import { formatEther, formatGwei, parseEther } from "viem";
// ETH price from any oracle or API (Chainlink, CoinGecko, etc.)
function useEthPrice(): number | undefined {
// In production, fetch from a price API or read Chainlink on-chain
// This is a placeholder -- replace with your price source
return 2500;
}
function GasEstimate({
to,
value,
}: {
to: `0x${string}`;
value: bigint;
}) {
const { data: gasLimit } = useEstimateGas({ to, value });
const { data: gasPrice } = useGasPrice();
const ethPrice = useEthPrice();
if (!gasLimit || !gasPrice || !ethPrice) {
return <span>Estimating fee...</span>;
}
// 10% safety margin on gas limit
const safeGasLimit = gasLimit + gasLimit / 10n;
const gasCostWei = safeGasLimit * gasPrice;
const gasCostEth = Number(formatEther(gasCostWei));
const gasCostUsd = gasCostEth * ethPrice;
return (
<div>
<p>Network fee: ~${gasCostUsd.toFixed(2)}</p>
<details>
<summary>Details</summary>
<dl>
<dt>Gas limit</dt>
<dd>{safeGasLimit.toString()}</dd>
<dt>Gas price</dt>
<dd>{formatGwei(gasPrice)} gwei</dd>
<dt>Cost in ETH</dt>
<dd>{gasCostEth.toFixed(6)} ETH</dd>
</dl>
</details>
</div>
);
}
Use useFeeHistory to compute slow/normal/fast gas tiers:
import { useFeeHistory } from "wagmi";
function useFeeTiers() {
const { data } = useFeeHistory({
blockCount: 5,
rewardPercentiles: [10, 50, 90],
});
if (!data?.reward || !data.baseFeePerGas) return undefined;
const latestBaseFee = data.baseFeePerGas[data.baseFeePerGas.length - 1];
if (!latestBaseFee) return undefined;
// Average priority fees at each percentile across recent blocks
const avgAt = (idx: number) =>
data.reward!.reduce((sum, r) => sum + (r[idx] ?? 0n), 0n) /
BigInt(data.reward!.length);
return [
{ label: "Slow", maxFeePerGas: latestBaseFee + avgAt(0) },
{ label: "Normal", maxFeePerGas: latestBaseFee * 2n + avgAt(1) },
{ label: "Fast", maxFeePerGas: latestBaseFee * 3n + avgAt(2) },
];
}
When a user connects on the wrong chain, prompt them immediately instead of letting them discover the error on their first transaction.
import { useAccount, useChainId, useSwitchChain } from "wagmi";
import type { ReactNode } from "react";
function RequireChain({
chainId: requiredChainId,
chainName,
children,
}: {
chainId: number;
chainName: string;
children: ReactNode;
}) {
const { isConnected } = useAccount();
const currentChainId = useChainId();
const { switchChain, isPending, error } = useSwitchChain();
if (!isConnected) return <>{children}</>;
if (currentChainId !== requiredChainId) {
return (
<div role="alert">
<p>This dApp requires {chainName}.</p>
<button
onClick={() => switchChain({ chainId: requiredChainId })}
disabled={isPending}
aria-busy={isPending}
>
{isPending ? "Switching..." : `Switch to ${chainName}`}
</button>
{error && <p>Failed to switch: {error.message}</p>}
</div>
);
}
return <>{children}</>;
}
When switchChain fails because the wallet doesn't know the chain, wagmi automatically calls wallet_addEthereumChain with the chain parameters from your config. The chain definition in wagmi already includes rpcUrls, blockExplorers, and nativeCurrency -- no extra configuration needed.
import { defineChain } from "viem";
// Custom chain definition with all required wallet_addEthereumChain fields
const myChain = defineChain({
id: 999999,
name: "My Network",
nativeCurrency: { name: "ETH", symbol: "ETH", decimals: 18 },
rpcUrls: {
default: { http: ["https://rpc.mynetwork.com"] },
},
blockExplorers: {
default: { name: "MyExplorer", url: "https://explorer.mynetwork.com" },
},
});
| Strategy | Approval Txs | Risk | UX |
|---|---|---|---|
Infinite approval (type(uint256).max) | 1 (once ever) | High: compromised spender drains all | Best: no future approvals needed |
| Exact amount | 1 per interaction | Low: only approved amount at risk | Worst: approval tx before every interaction |
| Permit2 (Uniswap) | 1 (once per token to Permit2) | Medium: time-limited permits | Good: off-chain signature per interaction |
The approval flow checks current allowance, then approves if needed:
import { useReadContract, useWriteContract, useAccount } from "wagmi";
const MAX_UINT256 = 2n ** 256n - 1n;
function useApprovalState(
token: `0x${string}`,
spender: `0x${string}`,
requiredAmount: bigint
) {
const { address } = useAccount();
const { data: allowance, refetch } = useReadContract({
address: token,
abi: erc20Abi,
functionName: "allowance",
args: address ? [address, spender] : undefined,
query: { enabled: !!address },
});
const needsApproval = allowance !== undefined && allowance < requiredAmount;
return { needsApproval, allowance, refetch };
}
Default to exact-amount approval (safer). Offer infinite approval (MAX_UINT256) as an opt-in with a warning about the risk. See examples/approval-flow/README.md for a complete component with Permit2 integration.
Permit2 (Uniswap's universal approval contract) replaces per-spender approvals with a single on-chain approval to the Permit2 contract (0x000000000022D473030F116dDEE9F6B43aC78BA3, same on all EVM chains -- last verified February 2026), then off-chain EIP-712 signatures for each subsequent interaction. The flow is:
token.approve(PERMIT2, maxUint256))PermitTransferFrom message with useSignTypedDatapermit2.permitTransferFrom() with the signatureSee examples/approval-flow/README.md for a complete Permit2 implementation.
Revoke by calling approve(spender, 0n). Always provide a revocation UI so users can remove approvals they no longer need. See examples/approval-flow/README.md for the full component.
WalletConnect v2 is the standard for connecting mobile wallets. It uses a relay server and requires a project ID from cloud.walletconnect.com.
import { walletConnect } from "wagmi/connectors";
walletConnect({
projectId: process.env.NEXT_PUBLIC_WC_PROJECT_ID!,
showQrModal: true,
metadata: {
name: "My dApp",
description: "Decentralized application",
url: "https://mydapp.com",
icons: ["https://mydapp.com/icon.png"],
},
})
Check navigator.userAgent for mobile wallet in-app browsers (metamask, coinbase, trust, rainbow). In-app browsers already have a provider injected and don't need WalletConnect. Regular mobile browsers require WalletConnect QR or deep links. Always guard with typeof window === "undefined" for SSR safety.
width: 100%)aria-busy on buttons during awaiting-signature and pending statesRun through every item before shipping. A missed state means a broken user experience.
number for token amounts -- always bigintNEXT_PUBLIC_ variables are exposed to the browser bundle. Never put private RPC keys with billing in NEXT_PUBLIC_ variables -- use a proxy or rate-limited public endpoint.contenthash to your IPFS deployment. Users access via yourname.eth.limo.docs/troubleshooting.md (opens in a new tab)examples/approval-flow/README.md (opens in a new tab)examples/connect-flow/README.md (opens in a new tab)examples/production-checklist/README.md (opens in a new tab)examples/transaction-flow/README.md (opens in a new tab)resources/accessibility-checklist.md (opens in a new tab)resources/chain-params.md (opens in a new tab)resources/error-codes.md (opens in a new tab)templates/dapp-page.tsx (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
Other plugins' skills for the same job
/frontend-ux:frontend-uxfrom frontend-ux
npx claudepluginhub naruto11eth/cryptoskills --plugin frontend-ux2 plugins ship this exact skill · first indexed Jul 19, 2026