β Master WalletConnect Integration
Understand QR sessions, message signing, and transaction approval
Integrate Web3 wallets into your dApp
Your Progress
0 / 5 completedβ Key Takeaways
π― Core Concepts
- πWallet = Web3 Passport: Your crypto wallet (MetaMask, Coinbase Wallet) is your universal identity across all dApps. One connection works everywhereβno accounts, no passwords, no 2FA. Private keys stay in your wallet, never exposed to websites.
- πConnection Detection: Check for
window.ethereumto detect browser wallets. Calleth_requestAccountsto request connection. User must approve in wallet popup. Handle rejection (error 4001) gracefully. - βοΈMessage Signing (Free): Used for authentication, voting (Snapshot), permits (EIP-2612). Zero gas cost. Signature proves wallet ownership without revealing private key. Verify with
ecrecoverorethers.verifyMessage(). - πTransaction Signing (Costs Gas): Modifies blockchain state. Users review: to address, value, data, gas cost. Wallet signs with private key, broadcasts to network. Irreversible once confirmed. Total cost = (gasLimit Γ gasPrice) + value.
- β½Gas = Transaction Fee: Paid in ETH to miners/validators. Simple transfer: 21,000 gas. Token swap: ~180,000 gas. Higher gas price = faster confirmation. EIP-1559: base fee (burned) + priority fee (to miner). Wallets estimate for users.
- β οΈSecurity: Trust but Verify: Always check: contract address (official?), token approvals (unlimited = dangerous), transaction simulation (unexpected transfers?). Mistakes are irreversible. Use tools like revoke.cash, Tenderly, Etherscan verification.
π οΈ Best Practices for Developers
Don't build from scratch. Use RainbowKit, ConnectKit, or web3modal. They handle: multi-wallet support, network switching, error handling, mobile (WalletConnect), and state management. Battle-tested by thousands of dApps.
Display human-readable summaries: "Swap 1 ETH β 2000 USDC" instead of raw hex data. Show expected outcomes. Use transaction simulation APIs. Clear previews prevent user errors and build trust.
Loading, connecting, connected, error, wrong network, rejected, account switched, disconnected. Show clear feedback for each state. Test with slow networks, mobile wallets, and user rejections.
accountsChanged, chainChanged, disconnect. Update UI immediately when user switches accounts or networks. Clean up listeners on unmount to prevent memory leaks.
π Real-World Examples
Uses RainbowKit for wallet connection. Shows transaction preview: "Swap 1 ETH for 2,041 USDC (slippage 0.5%)". Simulates transaction before signing. Displays gas cost in USD. One-click approval + swap bundling.
Uses message signing for authentication: "Sign this message to prove you own this wallet". No password needed. Gasless login. Signs off-chain orders (Seaport protocol) to list NFTs without immediate gas cost. Only buyer pays gas.
100% gasless voting via message signing. Users sign vote (FOR/AGAINST), signature stored off-chain. Votes aggregated and displayed. Optional on-chain execution via SafeSnap if proposal passes. Enables participation without ETH for gas.
π Test Your Knowledge
Take a 5-question quiz to verify your understanding of wallet connection, message signing, transaction signing, and gas mechanics.