Skip to content

Optimization: Migrate from ethers.js to viem for smaller bundle size #72

@jubalm

Description

@jubalm

Problem

The ethers.js library is large (~200KB minified), which impacts initial page load times and bundle size for the website.

Proposed Solution

Migrate from ethers.js to viem (a lighter, tree-shakeable Ethereum library ~15KB) for the blockchain data collection script.

Scope

  • scripts/calculate-fork-risk.ts - the only file using ethers.js
  • No changes to frontend code

Risk & Verification Needed

This is a critical data pipeline - the script calculates real fork risk values displayed on the live site. Before switching:

  1. Add test coverage to verify fork risk calculations
  2. Compare output before/after migration (run both versions against same RPC)
  3. Coordinate timing with low-traffic period for quick rollback if needed

Technical Notes

  • ethers.js v6 is currently being used
  • viem has similar APIs but may require refactoring RPC calls
  • Consider keeping both temporarily with a flag to switch between them

Impact

  • Bundle size reduction: ~185KB (estimated)
  • Improved Time to Interactive (TTI)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions