wagmi

Implement type-safe Ethereum dApp frontends using wagmi v2 React hooks and viem.

6|20|Updated Mar 14, 2026
One-click install
npx skills add https://github.com/andresdefi/cryptoskills --skill wagmi-andresdefi
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: wagmi
Source: https://github.com/andresdefi/cryptoskills/tree/main/skills/wagmi
Command: npx skills add https://github.com/andresdefi/cryptoskills --skill wagmi-andresdefi

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? AI agents trained on pre-2024 data generate outdated wagmi v1 code with removed APIs like WagmiConfig, useContractRead, and usePrepareContractWrite, causing broken builds and runtime errors in Ethereum dApp frontends. ## Core Features & Use Cases - wagmi v2 Hook Patterns: Correct usage of useAccount, useConnect, useReadContract, useWriteContract, useSimulateContract, useWaitForTransactionReceipt, useSwitchChain, and ENS hooks with TanStack Query integration. - Production Patterns: Approve-then-execute flows, multicall batched reads, SSR/Next.js hydration with cookie storage, EIP-6963 multi-wallet discovery, and revert reason parsing. - Reference Material: Connector comparison, error code tables, hook reference, troubleshooting guide, a starter app template, and four complete example projects (connect wallet, read contract, write transaction, multi-chain config). - Use Case: Build a Next.js dApp that connects MetaMask and WalletConnect, reads USDC balances across Ethereum, Arbitrum, and Base, and executes an ERC-20 approve-then-deposit flow with proper error handling. ## Quick Start Ask the agent to scaffold a wagmi v2 app with WagmiProvider, QueryClientProvider, wallet connection, and a contract read for a given token address.

Frequently Asked Questions about wagmi

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I migrate from wagmi v1 to v2?

Replace WagmiConfig with WagmiProvider, add a QueryClientProvider wrapper, and use createConfig with per-chain transports instead of createClient. Rename hooks: useContractRead becomes useReadContract, useContractWrite becomes useWriteContract, and usePrepareContractWrite is replaced by useSimulateContract.

How do I read a smart contract with wagmi React hooks?

Use useReadContract with the contract address, an ABI declared with as const, the function name, and args. The hook returns data typed from the ABI, plus isLoading and error states from TanStack Query. For batched reads, use useReadContracts to send a single multicall.

Why does wagmi throw 'No QueryClient set' error?

wagmi v2 delegates all caching to TanStack Query, so the app must be wrapped in both WagmiProvider and QueryClientProvider. Create a QueryClient instance and pass it to QueryClientProvider inside WagmiProvider.

Does wagmi v2 work with Next.js server-side rendering?

Yes, set ssr: true in createConfig and use cookieStorage via createStorage. In the root layout, call cookieToInitialState with the request cookies and pass the result to WagmiProvider to avoid hydration mismatches.

How do I handle ERC-20 approval before a contract write?

Read the current allowance with useReadContract, compare it to the required amount, and call approve via useWriteContract only if the allowance is insufficient. Wait for the approval receipt with useWaitForTransactionReceipt, refetch the allowance, then execute the main transaction.

Why is my wagmi ABI type inference not working?

The ABI array must be declared with as const for TypeScript to infer function names, argument types, and return types. Without as const, args become unknown[] and autocomplete is lost.