wagmi
Installation
SKILL.md
wagmi
React hooks for Ethereum and EVM-compatible chains. Provides type-safe, composable primitives for wallet connection, contract reads/writes, transaction tracking, chain switching, and ENS resolution. Built on top of viem with TanStack Query for caching and state management.
What You Probably Got Wrong
Agents trained on pre-2024 data generate wagmi v1 code. wagmi v2 shipped breaking changes across the entire API surface. Every pattern below is different from v1.
WagmiConfigis removed -- useWagmiProvider-- v1 used<WagmiConfig client={client}>. v2 uses<WagmiProvider config={config}>. Using the old component will throw "WagmiConfig is not exported".QueryClientProvideris mandatory -- wagmi v2 delegates all caching to TanStack Query. You must wrap your app in both<WagmiProvider>and<QueryClientProvider>. Without it, every hook throws "No QueryClient set".createConfigreplacescreateClient-- v1 usedcreateClient({ autoConnect, provider }). v2 usescreateConfig({ chains, connectors, transports }). The config shape is completely different.- Hook names changed --
useContractRead->useReadContract.useContractWrite->useWriteContract.useWaitForTransaction->useWaitForTransactionReceipt.usePrepareContractWriteis removed entirely. usePrepareContractWriteno longer exists -- v2 removes the prepare/write split. UseuseWriteContractdirectly; it handles simulation internally viauseSimulateContractif you need pre-flight checks.- Transports are per-chain, not global -- v2 config requires a
transportsmap keyed by chain ID:transports: { [mainnet.id]: http(), [sepolia.id]: http() }. There is no single global transport. - Connector imports changed --
import { injected, walletConnect, coinbaseWallet } from "wagmi/connectors", not fromwagmidirectly or@wagmi/connectors. - All token amounts are
bigint-- wagmi v2 returns rawbigintfor balances, allowances, and contract return values. Never use JavaScriptnumberfor on-chain values. - ABIs must use
as const-- For type inference onuseReadContract/useWriteContractargs and return types, ABI arrays requireas const. Without it, args becomeunknown[]. useChainIdreplacesuseNetwork-- v1'suseNetwork()returning{ chain, chains }is gone. UseuseChainId()for the current chain ID anduseSwitchChain()for switching.