Skip to content

Conversation

@dawsbot
Copy link
Owner

@dawsbot dawsbot commented Jan 30, 2026

🪶 viem → essential-eth Migration Codemod

A zero-dependency CLI tool that scans a codebase for viem imports and rewrites them to use essential-eth where an equivalent utility exists.

Usage

npx tsx scripts/migrate.ts ./src --dry-run   # preview changes
npx tsx scripts/migrate.ts ./src              # apply changes

Migration Map (19 functions)

viem essential-eth Notes
formatEther weiToEther renamed
parseEther etherToWei renamed
formatUnits formatUnits same
parseUnits parseUnits same
formatGwei gweiToEther renamed
parseGwei etherToGwei renamed
getAddress getAddress same
isAddress isAddress same
keccak256 keccak256 same
hashMessage hashMessage same
toHex hexlify renamed
toBytes arrayify renamed
concat concat same
pad zeroPad renamed
trim stripZeros renamed
isHex isHexString renamed
isBytes isBytes same
namehash namehash same
encodePacked pack renamed

Example Output (from test fixture)

🪶 essential-eth migration tool (dry run)

Scanning ./scripts/migrate-test-fixture...

✅ bytes.ts
   - toHex → hexlify
   - toBytes → arrayify
   - isHex → isHexString
   - concat → concat (same name)
   - isBytes → isBytes (same name)

⚠️  hashing.ts
   - keccak256 → keccak256 (same name)
   - encodePacked → pack
   - hashMessage → hashMessage (same name)
   ⚠️  createPublicClient — not available in essential-eth
   ⚠️  http — not available in essential-eth

✅ utils.ts
   - formatEther → weiToEther
   - parseEther → etherToWei
   - isAddress → isAddress (same name)
   - getAddress → getAddress (same name)

---
📊 Summary:
   Files scanned: 3
   Files with viem imports: 3
   Imports migrated: 12
   Imports unsupported: 2

Features

  • Recursive scanning of .ts, .tsx, .js, .jsx files
  • Import splitting — if only some symbols from a viem import are supported, it splits the import: supported → essential-eth, unsupported → stays on viem
  • Usage rewriting — renames all usages in the file body (e.g. formatEther(x)weiToEther(x))
  • Dry run mode--dry-run previews changes without modifying files
  • Exit code 1 when unsupported imports remain (CI-friendly)
  • Zero external dependencies — only uses Node built-ins

Files Added

  • scripts/migrate.ts — the migration CLI
  • scripts/migrate-test-fixture/ — 3 test fixture files for verification
  • MIGRATION.md — documentation

What is Next

  • ethers.js → essential-eth migration support
  • npx essential-eth migrate ./src (publish as bin)
  • Type alias handling (import type { ... } from "viem")
  • Re-export / barrel file support

@vercel
Copy link

vercel bot commented Jan 30, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
essential-eth Error Error Feb 7, 2026 9:48pm

up506920 and others added 3 commits February 7, 2026 14:48
Add scripts/migrate.ts — a zero-dependency CLI tool that scans a codebase
for viem imports and rewrites them to use essential-eth where an equivalent
utility exists.

Features:
- Recursively scans .ts/.tsx/.js/.jsx files
- Maps 19 viem utility functions to essential-eth equivalents
- Handles renamed functions (e.g. formatEther → weiToEther)
- Renames all usages in the file body, not just the import
- Splits partially-supported imports (keeps viem for unsupported symbols)
- --dry-run mode for safe previewing
- Clear summary with unsupported import report
- Exit code 1 when unsupported imports remain

Also adds:
- MIGRATION.md — documentation for the migration tool
- scripts/migrate-test-fixture/ — test fixtures for verification
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants