AAsyfdzaky

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.

wagmiwagmi-v2migrationweb3ethereumtanstack-query
Public
0 executions

Run locally

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
useContractReaduseReadContract
useContractWriteuseWriteContract
usePrepareContractWriteuseSimulateContract
useWaitForTransactionuseWaitForTransactionReceipt
useSwitchNetworkuseSwitchChain
WagmiConfigWagmiProvider
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

Usage

bash

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 (useContractReaduseReadContract 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: WagmiConfigWagmiProvider (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

Publish to Registry

bash

Compatibility

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

License

MIT

Author

asyifadzaky.11@gmail.com

Before

This is one example from the codemod's test cases. The codemod may handle many more cases.

Ready to contribute?

Build your own codemod and share it with the community.