Ggaibianshiji

ethersjs-v5-to-v6-migration

Automated migration from ethers.js v5 to v6. Covers 80%+ of deterministic changes: import paths, namespace flattening, BigNumber→bigint, contract patterns, provider/signer renames, and utility function updates.

ethersethersjsmigrationv5v6web3ethereumblockchainbigintcodemod
Public
0 executions

Run locally

npx codemod ethersjs-v5-to-v6-migration

ethers-v5-to-v6

Automated codemod for migrating ethers.js v5 codebases to v6.

What it does

This codemod automates ~90% of the deterministic migration patterns from ethers.js v5 to v6:

  • Import paths: @ethersproject/* sub-packages → unified "ethers" package
  • Namespace flattening: ethers.providers.X, ethers.utils.X, ethers.constants.Xethers.X
  • BigNumber → bigint: BigNumber.from()BigInt(), chained arithmetic
  • Contract patterns: callStatic.XX.staticCall(), estimateGas.XX.estimateGas()
  • Provider/Signer renames: Web3ProviderBrowserProvider, SignerAbstractSigner
  • Utility functions: arrayifygetBytes, splitSignatureSignature.from(), etc.
  • Constants: ethers.constants.AddressZeroethers.ZeroAddress, numeric constants → bigint literals

Usage

bash

Or run the migration script directly:

bash

What's NOT automated

These patterns require type information or semantic understanding and should be handled by an AI agent or manually:

  • Variable BigNumber arithmetic: balance.mul(2)balance * 2 (need to verify balance is bigint)
  • Removed APIs: commify(), poll(), checkProperties(), deepCopy()
  • feeData.lastBaseFeePerGas → alternative approach
  • Error code type changes (numeric → string)
  • provider.getNetwork().chainId type change (number → bigint)

Testing

bash

Case Study

See CASE_STUDY.md for the full migration analysis of Uniswap v3-periphery.

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.