DDeewakarBora

ethers-v5-to-v6-codemod

Automatically migrates ethers.js v5 code to v6 using jssg. Supports JavaScript and TypeScript.

upgradebreaking-changev5-to-v6ethers
Public
0 executions
Run locally
npx codemod ethers-v5-to-v6-codemod
Documentation

ethers-v5-to-v6-codemod

jssg
ethers
coverage
false positives
language

A production-grade automated migration toolkit that transforms ethers.js v5 code to v6 using 12 jssg (JavaScript ast-grep) transforms. Covers ~95% of all real-world migration patterns with zero false positives.


Quick Start

bash

Tip: Always test on a copy of your project first.


What Gets Migrated

TransformWhat it doesExample
transform1Utils functionsethers.utils.formatEtherethers.formatEther
transform2BigNumber → BigIntBigNumber.from("100")BigInt("100")
transform3Provider renamesethers.providers.Web3Providerethers.BrowserProvider
transform4Crypto utilsethers.utils.keccak256ethers.keccak256
transform5callStaticcontract.callStatic.foo()contract.foo.staticCall()
transform6Contract addresscontract.addresscontract.target
transform7Transactionsprovider.sendTransaction(hex)provider.broadcastTransaction(hex)
transform8Signaturesethers.utils.splitSignature(sig)ethers.Signature.from(sig)
transform9Import cleanupRemoves deprecated BigNumber and providers imports
transform10Gas + hex utilsprovider.getGasPrice()provider.getFeeData()
transform11Contract methodscontract.estimateGas.foo()contract.foo.estimateGas()
transform12Sub-package imports@ethersproject/unitsethers

Real-World Results

Tested on thallo-io/ethers-js-cheatsheet — a real open-source TypeScript project.

6 files transformed · 0 errors · 0 false positives

Example: Uniswap Quote Script

Before:

typescript

After:

typescript

Edge Cases

For the remaining ~5%, see AI-INSTRUCTIONS.md which documents 11 edge cases requiring manual or AI-assisted handling, including:

  • BigNumber TypeScript type annotations → bigint
  • ethers.utils.commify replacement (removed in v6)
  • ethers.utils.fetchJsonFetchRequest class rewrite
  • Custom provider subclass updates
  • contract.deployed() removal
  • provider.waitForTransactionwaitForTransactionReceipt

How It Works

jssg (JavaScript ast-grep) parses your source files into an Abstract Syntax Tree (AST). Each transform uses pattern matching to find specific v5 patterns and replaces them with their v6 equivalents, preserving your original formatting and comments.

Because transforms operate on the AST rather than raw text, replacements are structurally exact — they cannot accidentally match code inside string literals or comments.


Project Structure

plaintext

Requirements

  • Node.js 16+
  • Codemod CLI (npx codemod)

License

MIT

Ready to contribute?

Build your own codemod and share it with the community.