Registry
AAsyfdzaky avatar

asyfdzaky-wagmi-v1-to-v2

Automates wagmi v1 → v2 migration. Covers hook renames, configureChains removal, WagmiConfig → WagmiProvider, and TanStack Query v5 callback patterns. 85%+ automation, zero false positives.

Asyfdzaky0 executions

  • wagmi
  • wagmi-v2
  • migration
  • web3
  • ethereum
  • tanstack-query
Connect a repo
npx codemod asyfdzaky-wagmi-v1-to-v2

wagmi-v1-to-v2

One command migrates your wagmi v1 codebase to v2. Deterministic AST transforms with zero false positives.
Tested on scaffold-eth-2 with 100% safety.

What it does

Automatically migrates the most common wagmi v1 → v2 patterns:

PatternMigration
useContractRead→ useReadContract
useContractWrite→ useWriteContract
usePrepareContractWrite→ useSimulateContract
useWaitForTransaction→ useWaitForTransactionReceipt
useSwitchNetwork→ useSwitchChain
WagmiConfig→ WagmiProvider
createClient (from wagmi only)→ createConfig
configureChains()Flagged with TODO
onSuccess/onError callbacksFlagged with TODO
autoConnect configFlagged with TODO
watch: trueFlagged with TODO

What needs manual follow-up

  • Connector API rewrites: InjectedConnector() → injected(), etc.
  • Custom useBalance() token param removals
  • Transport configuration setup
  • TanStack Query v5 migration patterns

Installation

bash
npm install -D codemod
# or
bunx codemod@latest add wagmi-v1-to-v2

Usage

bash
# Run locally in current project
npx codemod workflow run -w node_modules/@your-org/wagmi-v1-to-v2

# Or with npx from registry (when published)
npx codemod @your-org/wagmi-v1-to-v2 --target ./src

Case Study: scaffold-eth-2

Repository: https://github.com/scaffold-eth/scaffold-eth-2
Branch: main (commit)

Results

  • Files changed: 1 (code transformations only; CLAUDE.md is skill metadata)
  • Hook renames applied: 5+ usages found and transformed
  • False positives: 0 (viem createClient correctly preserved)
  • TypeScript errors before: 0
  • TypeScript errors after: 0
  • Compile-time safety: ✅ Verified

Key Evidence

The migration successfully avoided false positives:

  • ✅ packages/nextjs/services/web3/wagmiConfig.tsx uses createClient from "viem" — correctly untouched
  • ✅ Hook comment references auto-updated (useContractRead → useReadContract in JSDoc)
  • ✅ Zero import errors or unresolved references
  • ✅ Zero new TS compilation errors

How it works

  1. rename-hooks: Global replacement of v1 hook names to v2 using exact word boundaries
  2. rename-provider: WagmiConfig → WagmiProvider (lexical substitution)
  3. migrate-config: Source-aware migration of createClient/createConfig:
    • ✅ Only renames if imported from "wagmi"
    • ✅ Skips imports/calls from "viem" or other sources
    • ✅ Preserves code formatting
  4. migrate-callbacks: Flags callback patterns with TODO comments for manual migration
  5. install-skill: Registers Claude MCP skill for AI-assisted edge cases

False Positive Policy

All transforms verify the import source before modifying code:

  • createClient from "wagmi" → renamed to createConfig
  • createClient from "viem" → left untouched
  • Ambiguous cases → flagged with TODO, never silently rewritten

Test Coverage

Local fixture tests verify:

  • ✅ Main transformation case (v1 → v2)
  • ✅ Already-v2 code (idempotent, no changes)
  • ✅ Aliased imports (preserves alias)
  • ✅ Local shadowing (respects local functions)
  • ✅ viem createClient (never renamed)
  • ✅ Idempotency (running twice = same result)

All tests pass with npx codemod jssg test.

Development

bash
# Validate workflow
npx codemod workflow validate -w workflow.yaml

# Run unit tests
npx codemod jssg test -l tsx ./scripts/rename-hooks.ts ./tests/rename-hooks
npx codemod jssg test -l tsx ./scripts/rename-provider.ts ./tests/rename-provider
npx codemod jssg test -l ts ./scripts/migrate-config.ts ./tests/migrate-config
npx codemod jssg test -l tsx ./scripts/migrate-callbacks.ts ./tests/migrate-callbacks

# Run on real codebase
npx codemod workflow run -w . -t ~/my-wagmi-v1-project --no-interactive --install-skill

Publish to Registry

bash
codemod login
codemod publish

Compatibility

  • ✅ TypeScript + TSX
  • ✅ wagmi v1.x → v2.x
  • ✅ Node.js 18+
  • ✅ Monorepos (processes all matching files)

License

MIT

Author

asyifadzaky.11@gmail.com

Ready to evolve your codebase?

Build tailored, compiler-aware skills to assess, plan, and automate complex codebase changes.