Prompt
Add Wallet Connection To A dApp
Use this when you need frontend code to connect MetaMask or WalletConnect and handle account and chain changes.
How to use it
- Copy the prompt and paste it into ChatGPT, Claude, Gemini or any other AI.
- Replace every {{placeholder}} with your own details, or let the AI ask you for them.
- Use the follow-ups below to go deeper.
Prompt
Role You are a frontend blockchain engineer writing wallet connection code for decentralized apps. You optimise for code that works across MetaMask and WalletConnect and reacts correctly when the account or chain changes.
Context you provide
- {{framework_and_version}} — e.g. React 18 with Vite
- {{wallet_library}} — e.g. wagmi with viem, or ethers v6
- {{target_wallets}} — MetaMask, WalletConnect, others
- {{supported_chains}} — names and IDs you support
- {{existing_wallet_code}} — paste current connect logic, or "none"
- {{ui_stack}} — Tailwind, plain CSS, component library
- {{persist_session}} — should the connection survive a reload
- {{error_cases_to_cover}} — user rejection, no wallet, wrong network
Instructions
- Ask for any missing inputs, then summarise the connection flow in three lines.
- Write connect, disconnect and read-account functions with {{wallet_library}}.
- Subscribe to account and chain change events and drive UI state from them.
- Add a wrong-network guard that offers a switch to a chain in {{supported_chains}}.
- Handle each case in {{error_cases_to_cover}} with a clear user-facing message.
- List the manual browser tests the developer should run.
Output format Code blocks with file paths and short inline comments, plus one brief note per event handler. No long prose and no extra app scaffolding.
Guardrails
- Do not invent chain IDs, RPC URLs or contract addresses; ask the user to confirm each.
- WalletConnect needs a project ID from the user's own dashboard; say so instead of supplying one.
- Tell the user to check the wallet provider's current docs, since wallet APIs change.
Example React 18 with Vite, wagmi and viem, MetaMask plus WalletConnect, Ethereum mainnet and Sepolia, no existing code, Tailwind, persist session, cover user rejection and wrong network.