Ddrakenkun-bot

drakenkun-bot-wagmi-v1-to-v2

Automates 80% of wagmi v1 to v2 migration

wagmiethereumweb3
Public
0 executions

Run locally

npx codemod drakenkun-bot-wagmi-v1-to-v2

wagmi v1 → v2 Migration Codemod

A production-grade codemod that automates ~80% of the wagmi v1 → v2 migration with zero false positives.

Built with the Codemod toolkit.


What it automates

PatternCoverageMethod
Hook renames (useContractReaduseReadContract, etc.)✅ AutomatedDeterministic
Connector renames + class→function (new WalletConnectConnectorwalletConnect())✅ AutomatedDeterministic
Connector import paths (wagmi/connectors/*@wagmi/connectors)✅ AutomatedDeterministic
WagmiConfigWagmiProvider (import + JSX)✅ AutomatedDeterministic
client= prop → config= prop✅ AutomatedDeterministic
package.json peer dependency upgrades✅ AutomatedDeterministic
createClientcreateConfig⚠️ FlaggedManual/AI
configureChains removal⚠️ FlaggedManual/AI
TanStack Query options → query: {}⚠️ FlaggedManual/AI
Mutation args moved to function⚠️ FlaggedManual/AI

Hook renames handled

v1v2
useContractReaduseReadContract
useContractReadsuseReadContracts
useContractWriteuseWriteContract
usePrepareContractWriteuseSimulateContract
usePrepareSendTransactionuseEstimateGas
useWaitForTransactionuseWaitForTransactionReceipt
useSwitchNetworkuseSwitchChain
useNetworkuseChainId
useWebSocketPublicClientusePublicClient

Connector renames handled

v1 (class)v2 (function)
new CoinbaseWalletConnector({...})coinbaseWallet({...})
new InjectedConnector()injected()
new MetaMaskConnector()injected()
new SafeConnector({...})safe({...})
new WalletConnectConnector({...})walletConnect({...})
new WalletConnectLegacyConnector({...})walletConnect({...})

Usage

bash

Output

The CLI:

  • ✅ Lists every file it changes
  • ⚠️ Prints all items needing manual/AI attention with links to docs
  • Tells you to run npm install after finishing

Running tests

bash

36 tests, all passing. Coverage includes:

  • Every hook rename
  • All connector transforms
  • Config API changes
  • Package.json upgrades
  • False positive prevention (hooks from non-wagmi libraries are never touched)
  • Full pipeline integration tests

Design principles

Zero false positives. The codemod tracks which hooks are actually imported from wagmi before touching any usage sites. A hook named useContractRead imported from some-other-lib is never renamed.

Detect, don't mangle. For patterns that require understanding control flow or object structure (TanStack Query options, mutation args), we detect and flag them with actionable error messages rather than risk producing incorrect code.

One transform per concern. Each transform file handles exactly one class of change, making them independently testable and easy to audit.


After running

  1. Run npm install to install upgraded dependencies
  2. Address all MANUAL: warnings in the output (these are the ~20% requiring human judgment)
  3. Run your build and test suite
  4. Key manual items:
    • Replace createClient + configureChains with createConfig + transports
    • Move TanStack Query options into query: {} on read hooks
    • Move mutation args from hook call to the returned function call

Resources

Ready to contribute?

Build your own codemod and share it with the community.