| name | web3-frontend |
| description | Web3 frontend integration with Viem, Wagmi, and Reown AppKit for Ethereum dApps. Use when building blockchain-connected UIs, implementing wallet connections, reading/writing smart contracts, or handling transactions. Triggers on tasks involving Viem clients, Wagmi hooks, Reown/RainbowKit configuration, multicall, or ERC-20/ERC-721 interactions. |
Web3 Integration Best Practices
Modern Web3 frontend development with Viem, Wagmi, and Reown AppKit.
Quick Reference
Installation
pnpm add viem wagmi @tanstack/react-query
pnpm add @reown/appkit @reown/appkit-adapter-wagmi
Core Pattern
import { createPublicClient, createWalletClient, http } from "viem";
import { mainnet } from "viem/chains";
const publicClient = createPublicClient({
chain: mainnet,
transport: http(),
});
const walletClient = createWalletClient({
chain: mainnet,
transport: custom(window.ethereum!),
});
const { request } = await publicClient.simulateContract({...});
const hash = await walletClient.writeContract(request);
const receipt = await publicClient.waitForTransactionReceipt({ hash });
Wagmi Hooks
import {
useReadContract,
useWriteContract,
useWaitForTransactionReceipt,
} from "wagmi";
const { data } = useReadContract({ address, abi, functionName, args });
const { writeContract, data: hash } = useWriteContract();
const { isLoading, isSuccess } = useWaitForTransactionReceipt({ hash });
Best Practices
- Viem - Type-safe, performant, modern
- Multicall - Batch reads to reduce RPC calls
- Simulate first - Catch errors before signing
- Handle all errors - Rejections, reverts, insufficient funds
- Loading states - Pending, confirming, success
- Reown AppKit - 400+ wallets, social logins