Current Version: ethers v5.8.0 Target Version: ethers v6.15.0 Status: Planning Phase Priority: High (Major Security & Feature Updates)
Ethers.js v6 is a major rewrite with significant breaking changes. This migration requires careful planning and comprehensive testing.
Migration Complexity: 🔴 HIGH Estimated Effort: 2-3 weeks Risk Level: Medium (with proper testing)
- ✅ Better TypeScript Support - Full native TypeScript rewrite
- ✅ Improved Performance - 20-30% faster for common operations
- ✅ Better Error Handling - More descriptive error messages
- ✅ Reduced Bundle Size - Tree-shaking optimizations
- ✅ Modern Features - ESM support, async/await improvements
- ✅ Security Updates - Latest vulnerability patches
- ✅ EIP-1559 Support - Better gas fee handling
⚠️ Security vulnerabilities in v5⚠️ Missing new chain features (EIP-4844, etc.)⚠️ No support for latest wallet standards⚠️ Community moving to v6 (less support for v5)
v5 (Current):
const { ethers } = require('ethers');
const provider = new ethers.providers.JsonRpcProvider(url);
const wallet = new ethers.Wallet(privateKey, provider);v6 (New):
const { ethers, JsonRpcProvider, Wallet } = require('ethers');
const provider = new JsonRpcProvider(url);
const wallet = new Wallet(privateKey, provider);Key Change: No more ethers.providers.* or ethers.utils.*
v5:
const provider = new ethers.providers.JsonRpcProvider(RPC_URL);
const balance = await provider.getBalance(address);
const block = await provider.getBlock('latest');v6:
const provider = new JsonRpcProvider(RPC_URL);
const balance = await provider.getBalance(address);
const block = await provider.getBlock('latest');Key Changes:
providers.JsonRpcProvider→JsonRpcProviderproviders.Web3Provider→BrowserProviderproviders.InfuraProvider→ UseJsonRpcProviderwith Infura URL
v5:
const contract = new ethers.Contract(address, abi, signerOrProvider);
const tx = await contract.transfer(to, amount);
const receipt = await tx.wait();v6:
const contract = new Contract(address, abi, signerOrProvider);
const tx = await contract.transfer(to, amount);
const receipt = await tx.wait(); // Same!Key Changes:
- Import Contract directly
- Most contract methods unchanged ✅
v5:
ethers.utils.parseEther('1.0')
ethers.utils.formatEther(wei)
ethers.utils.keccak256(data)
ethers.utils.hexlify(value)
ethers.utils.getAddress(address)v6:
parseEther('1.0')
formatEther(wei)
keccak256(data)
hexlify(value)
getAddress(address)Key Change: Import utils directly, no more ethers.utils.*
v5:
const value = ethers.BigNumber.from('1000000000000000000');
const sum = value.add(ethers.BigNumber.from('1'));v6:
const value = BigInt('1000000000000000000');
const sum = value + BigInt('1'); // Native BigInt!Key Change: Native JavaScript BigInt replaces ethers.BigNumber
v5:
const filter = contract.filters.Transfer(null, address);
const events = await contract.queryFilter(filter, startBlock, endBlock);v6:
const filter = contract.filters.Transfer(null, address);
const events = await contract.queryFilter(filter, startBlock, endBlock);
// Mostly unchanged ✅- Inventory all ethers.js usage in codebase
- Identify files using ethers (use grep):
grep -r "require.*ethers" --include="*.js" grep -r "from.*ethers" --include="*.js"
- Document all API patterns currently used
- Create migration branch:
git checkout -b feature/ethers-v6 - Set up parallel testing environment
- Ensure all existing tests pass on v5
- Update package.json:
"ethers": "^6.15.0" - Run
npm installon test environment - Document any peer dependency issues
Files likely using ethers:
smart-contracts-integration.jsweb3-wallet-integration.jscontract-abis.jswithdrawal-*.jsscripts- Any files with
web3-prefix
Migration Steps per File:
- Read file and identify ethers usage
- Update imports/requires
- Replace
ethers.providers.*with direct imports - Replace
ethers.utils.*with direct utils - Replace
ethers.BigNumberwithBigInt - Test thoroughly
Before (v5):
const { ethers } = require('ethers');
async function getBalance(address) {
const provider = new ethers.providers.JsonRpcProvider(process.env.RPC_URL);
const balance = await provider.getBalance(address);
return ethers.utils.formatEther(balance);
}
const amount = ethers.utils.parseEther('1.5');
const bigNum = ethers.BigNumber.from('1000');After (v6):
const { JsonRpcProvider, formatEther, parseEther } = require('ethers');
async function getBalance(address) {
const provider = new JsonRpcProvider(process.env.RPC_URL);
const balance = await provider.getBalance(address);
return formatEther(balance);
}
const amount = parseEther('1.5');
const bigNum = BigInt('1000');- Update all unit tests for v6 syntax
- Run full test suite:
npm test - Achieve same code coverage as v5
- Test wallet connections
- Test contract deployments
- Test contract interactions (read/write)
- Test event listening
- Test transaction signing
- Connect MetaMask wallet
- Test LTD token transfers
- Test tanda group creation
- Test withdrawal flow
- Test staking functions
# Find all files importing ethers
find . -name "*.js" -type f -exec grep -l "ethers" {} \;Expected Files:
/smart-contracts-integration.js/web3-wallet-integration.js/web3-dashboard.js/contract-abis.js/smart-contracts/scripts/*.js/smart-contracts/test/*.js
- Any API endpoints using blockchain
- Withdrawal processing scripts
- Balance checking utilities
- Documentation examples
- Test fixtures
- Mock data
# Run all existing tests
npm test
# Test contract interactions
npm run test:contracts
# Manual wallet tests
# 1. Connect wallet
# 2. Check balance
# 3. Send transaction
# 4. Verify on PolygonScan# Same tests should pass
npm test
npm run test:contracts
# Additional v6 specific tests
# 1. BigInt operations
# 2. Error handling
# 3. Gas estimation
# 4. Event filteringProblem:
// This will break in v6
const total = balance.add(amount);Solution:
// Use native BigInt operations
const total = balance + amount;
// For multiplication/division
const doubled = balance * BigInt(2);
const half = balance / BigInt(2);Problem:
// Trying to do math with formatted value
const formatted = formatEther(balance);
const doubled = formatted * 2; // NaN!Solution:
// Do math with BigInt, then format
const doubled = balance * BigInt(2);
const formattedDoubled = formatEther(doubled);Problem:
// v5 - This will break
const provider = new ethers.providers.Web3Provider(window.ethereum);Solution:
// v6 - Use BrowserProvider
import { BrowserProvider } from 'ethers';
const provider = new BrowserProvider(window.ethereum);If migration fails:
-
Quick Rollback:
git checkout main git branch -D feature/ethers-v6
-
Package Rollback:
npm install ethers@5.8.0
-
Deploy Previous Version:
git revert <migration-commit> npm install npm run production
- Migration Guide: https://docs.ethers.org/v6/migrating/
- v6 Documentation: https://docs.ethers.org/v6/
- Changelog: https://github.com/ethers-io/ethers.js/blob/main/CHANGELOG.md
- Stack Overflow: [ethers.js v6] tag
- GitHub Discussions: https://github.com/ethers-io/ethers.js/discussions
- Discord: Ethers.js community
| Week | Phase | Tasks | Status |
|---|---|---|---|
| Week 1 | Preparation | Code analysis, branch setup | ⏳ Pending |
| Week 2 | Migration | Update code, fix imports | ⏳ Pending |
| Week 3 | Testing | Unit, integration, manual tests | ⏳ Pending |
| Week 4 | Deploy | Staging → Production | ⏳ Pending |
Before deploying to production:
- All unit tests passing (100% coverage maintained)
- All integration tests passing
- Manual wallet connection works
- Contract interactions work (read & write)
- Transaction signing works
- Event listening works
- No console errors in browser
- Performance same or better than v5
- Bundle size reduced or same
- Code review completed
- Documentation updated
- Review this migration guide with team
- Get approval to proceed
- Create feature branch
- Run code analysis to find all ethers usage
- Perform migration in test environment
- Run comprehensive tests
- Fix any issues found
- Deploy to staging
- Monitor for issues
- Deploy to production
Document Version: 1.0 Last Updated: November 18, 2025 Owner: Development Team Reviewer: TBD Approval: Pending