WWaleedbhattiii

waleedbhattiii-wagmi-v1-to-v2

Migrate wagmi v1 to v2. Automates hook renames, provider changes, connector refactors, query param restructuring, and more. Covers ~85% of the migration deterministically with an AI step for edge cases.

upgradebreaking-changev1-to-v2wagmireactweb3ethereumdefiviemtanstack-query
Public
0 executions
Run locally
npx codemod waleedbhattiii-wagmi-v1-to-v2
Documentation

wagmi v1 → v2 Codemod

Automates the wagmi v1 to v2 migration.
Built with the Codemod JSSG engine.
Published: waleedbhattiii-wagmi-v1-to-v2

Quick Start

bash

Or run manually on a specific directory:

bash

What gets migrated automatically (~85% coverage)

Categoryv1v2
Provider<WagmiConfig><WagmiProvider>
HookuseContractReaduseReadContract
HookuseContractWriteuseWriteContract
HookuseContractEventuseWatchContractEvent
HookuseContractReadsuseReadContracts
HookuseContractInfiniteReadsuseInfiniteReadContracts
HookuseWaitForTransactionuseWaitForTransactionReceipt
HookuseSwitchNetworkuseSwitchChain
HookuseSigneruseWalletClient
HookuseProviderusePublicClient
HookuseWebSocketProviderusePublicClient
HookuseFeeDatauseEstimateFeesPerGas
Prepare hooksusePrepareContractWriteuseSimulateContract
Prepare hooksusePrepareSendTransactionuseEstimateGas
Query paramsuseReadContract({ enabled })useReadContract({ query: { enabled } })
Watch propuseBalance({ watch: true })Removed + TODO added
Connectorsnew MetaMaskConnector({ chains })metaMask()
Connectorsnew WalletConnectConnector(...)walletConnect(...)
Connectorsnew InjectedConnector(...)injected(...)
Connectorsnew CoinbaseWalletConnector(...)coinbaseWallet(...)
ConfigcreateClientcreateConfig
NetworkuseNetwork()useChainId() + useChains()
ImportsStale v1 specifiersCleaned up

Key safety guarantees:

  • Import source verified before any rename — user-defined hooks with same names are never touched
  • Exact text match prevents substring collisions (e.g. useContractRead never matches useContractReads)
  • String-aware comma splitting — commas inside string values never cause incorrect splits
  • watch: true preserved on useBlockNumber and useBlock (still valid in v2)
  • Non-overlapping edits — TODO comments inserted before statements, never inside renamed nodes
  • useSwitchNetwork renamed in-place by transform 01, not removed by transform 08

What needs manual work (flagged with TODO)

PatternWhy manual
configureChainsRequires Viem transport setup specific to each RPC provider
watch: true removalReplacement pattern depends on component structure
usePrepareContractWrite destructuringconfigdata.request
useNetwork().chainReturns chainId (number not Chain object)
useWriteContract argsContract config moves from hook to writeContract() call site
useSwitchChain resultswitchNetworkswitchChain
useWalletClient resultViem WalletClient not ethers Signer
useWaitForTransactionReceipt hashType changes from string to 0x${string}

Install wagmi v2 peer dependencies

bash

Wrap your app with QueryClientProvider

tsx

Running tests

bash

Or individually:

bash

Real-world benchmark

Tested on the official wagmi v1 examples (wevm/wagmi@1.x branch):

  • 27 files scanned
  • 10 files changed automatically
  • ~85% of migration patterns automated
  • 6 TODO comments added for AI/manual resolution
  • 0 false positives

Project structure

plaintext
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.