migrating-an-onchainkit-app
Original:🇺🇸 English
Not Translated
Migrates apps from @coinbase/onchainkit to standalone wagmi/viem components. Handles provider replacement (OnchainKitProvider to WagmiProvider), wallet component replacement (Wallet/ConnectWallet to custom WalletConnect), and transaction component replacement. Use when the user says "migrate my onchainkit", "replace onchainkit provider", "migrate my wallet component", "replace my onchainkit wallet", "migrate my transaction component", "remove onchainkit dependency", or "move off onchainkit".
2installs
Sourcebase/base-skills
Added on
NPX Install
npx skill4agent add base/base-skills migrating-an-onchainkit-appSKILL.md Content
OnchainKit Migration Skill
Migrate apps from to standalone / components with zero OnchainKit dependency.
@coinbase/onchainkitwagmiviemBefore Starting
Create a file in the project root:
mistakes.mdmarkdown
# Migration Mistakes & Learnings
Track errors, fixes, and lessons learned during OnchainKit migration.
## Errors
## Lessons LearnedAppend every error, fix, and lesson to this file throughout the migration. This file improves the skill over time.
Migration Workflow
Migrations MUST happen in this order. Do not skip steps.
Step 1: Detection
Scan the project to understand current OnchainKit usage:
- Search all files for imports
@coinbase/onchainkit - Identify which components are used:
- Provider: (always present if using OnchainKit)
OnchainKitProvider - Wallet: ,
Wallet,ConnectWallet,WalletDropdown,WalletModalConnected - Transaction: ,
Transaction,TransactionButtonTransactionStatus - Other: ,
Identity,Avatar,Name,Address,Swap, etc.Checkout
- Provider:
- Check for existing
package.json,wagmi,viemdependencies@tanstack/react-query - Identify the project's styling approach (Tailwind, CSS Modules, styled-components, etc.)
- Report findings to the user before proceeding
Step 2: Provider Migration (always first)
Read references/provider-migration.md for detailed instructions and code.
Summary:
- Ensure ,
wagmi, andviemare installed@tanstack/react-query - Create with chain and connector configuration
wagmi-config.ts - Replace with
OnchainKitProvider+WagmiProviderQueryClientProvider - Remove import
@coinbase/onchainkit/styles.css - Remove any or MiniKit imports from layout files
SafeArea
Validation gate: Run (or the project's build command). Must pass before continuing. If it fails, fix errors and document them in .
npm run buildmistakes.mdStep 3: Wallet Migration (after provider)
Read references/wallet-migration.md for detailed instructions and code.
Summary:
- Create a component using wagmi hooks (
WalletConnect,useAccount,useConnect)useDisconnect - Component includes a modal with wallet options: Base Account, Coinbase Wallet, MetaMask
- Shows truncated address + disconnect button when connected
- Replace all OnchainKit wallet imports and component usage
Validation gate: Run . Must pass before continuing. Document any errors in .
npm run buildmistakes.mdStep 4: Transaction Migration (after wallet)
Read references/transaction-migration.md for detailed instructions and code.
Summary:
- Check the prop on existing
chainIdcomponents -- add any missing chains to<Transaction />wagmi-config.ts - Create a component using wagmi hooks (
TransactionForm,useWriteContract,useWaitForTransactionReceipt)useSwitchChain - Component handles the full lifecycle: idle, pending wallet confirmation, confirming on-chain, success, error
- Replace all OnchainKit transaction imports (,
Transaction,TransactionButton,TransactionStatus, etc.)TransactionSponsor - Update the array format -- use
calls,address,abi,functionNamewith properargstypingas const - Map callback to the new lifecycle status names (init, pending, confirmed, success, error)
onStatus
Validation gate: Run . Must pass before continuing. Document any errors in .
npm run buildmistakes.mdStep 5: Cleanup
- Search for any remaining imports -- there should be none
@coinbase/onchainkit - Optionally remove from
@coinbase/onchainkitdependenciespackage.json - Run final to verify everything works
npm run build - Update with final lessons learned
mistakes.md
Troubleshooting
Build fails after provider migration
- Missing dependencies: Ensure ,
wagmi,viemare installed@tanstack/react-query - Type errors with wagmi config: Check that array has at least one chain and
chainshas a matching entrytransports - "use client" missing: Both the provider and wallet components must have directive
"use client"
MetaMask SDK react-native warning
- The warning is harmless in web builds. It comes from MetaMask SDK and does not affect functionality.
Can't resolve '@react-native-async-storage/async-storage'
Wallet won't connect
- Verify the wagmi config has the correct connectors configured
- Check that wraps the component tree before any wallet hooks are used
WagmiProvider - Ensure is inside
QueryClientProviderWagmiProvider
Transaction receipt stuck in pending
- Symptom: Transaction hash appears, tx confirms on-chain, but UI stays stuck on "Transaction in progress..." forever
- Cause: has no RPC to poll because the transaction's chain is missing from the wagmi config's
useWaitForTransactionReceipt+chainstransports - Fix: (1) Add the target chain to chains array AND transports object. (2) Always pass
wagmi-config.tstochainIdso it polls the correct chainuseWaitForTransactionReceipt({ hash, chainId })
Transaction targets wrong chain
- The auto-switches chains, but the target chain must exist in the wagmi config's
TransactionFormarray andchainsobjecttransports - Common: add for testnet transactions (chainId 84532)
baseSepolia
Next.js page export restrictions
- Next.js only allows specific named exports from page files. Exporting contract call arrays or ABI constants from a page file will cause a build error
- Fix: make them non-exported declarations or move them to a separate module
const
ABI type errors after transaction migration
- When defining ABIs inline, use on the array for proper type inference
as const - Mark individual fields like and
type: 'function' as conststateMutability: 'nonpayable' as const
Existing wagmi setup detected
- If the project already wraps with , do NOT add another one
WagmiProvider - Instead, just update the existing wagmi config to include the needed connectors
- OnchainKit's provider detects and defers to existing wagmi providers -- the standalone setup should too
Important Notes
- Always use and
wagmidirectly. Never import fromviem.@coinbase/onchainkit - The connector comes from
baseAccount, not from a separate package.wagmi/connectors - must include every chain the app transacts on. If the original OnchainKit
wagmi-config.tsused a specific chain, that chain must be in both<Transaction chainId={X} />andchains. Without it,transportswill hang forever.useWaitForTransactionReceipt - If the project uses Tailwind, use Tailwind classes for the components. If not, adapt to inline styles or the project's existing styling approach (e.g., CSS Modules).
- Do not export contract call arrays, ABI constants, or other non-page values from Next.js page files. Use non-exported constants or a separate module.
- Inspect the OnchainKit source code in if you need to understand how a specific component works internally.
node_modules/@coinbase/onchainkit/src/