Skip to content

Ethers -> Viem migration#7061

Merged
shoom3301 merged 356 commits intodevelopfrom
bernardo/cow-572-m7-cleanup-documentation
Apr 14, 2026
Merged

Ethers -> Viem migration#7061
shoom3301 merged 356 commits intodevelopfrom
bernardo/cow-572-m7-cleanup-documentation

Conversation

@bsvalverde
Copy link
Copy Markdown
Collaborator

@bsvalverde bsvalverde commented Feb 21, 2026

Summary

Preview links:

This PR removes ethers entirely and migrates all blockchain interaction logic to a wagmi + viem-centric architecture.

This PR was built up incrementally through the following PRs. Note that a small number of commits were also made directly to this branch and are not associated with a separate PR.

What Changed

1. Dependency Removal

  • Removed ethers
  • Removed multicall
  • Removed web3-react
  • Eliminated all contract instance abstractions and interfaces

2. Contract Interaction Refactor

  • Replaced instance-based contract usage with wagmi readContract / writeContract
  • Replaced manual multicall usage with wagmi’s built-in multicall support
  • Minimized direct wallet provider access
  • Removed manual signer plumbing
  • Updated Cow SDK to use the viem adapter instead of the ethers v5 adapter

Signer resolution is now handled automatically by the wagmi adapter (connected wallet signer or default permit account where applicable).

3. ethersviem Migration

All ethers utilities have been replaced with their viem equivalents:

  • Hex transformations → viem utilities
  • ABI encoding/decoding → viem encoding helpers
  • BigNumber → native bigint
  • Unit parsing/formatting → viem helpers

This removes the BigNumber abstraction entirely and standardizes numeric handling on bigint.


To Test

  • Perform a full regression of the app to ensure all existing functionality works correctly. This includes wallet connections, contract reads/writes, permit flows, and numeric handling.

Here are recorded demos of:


Background

Previously, the project relied on:

  • ethers for providers, signers, contract instances, encoding utilities, and BigNumber
  • web3-react for wallet/provider management
  • A separate multicall library for batched reads
  • Direct provider and signer access throughout the codebase

This created:

  • Overlapping abstractions between ethers, web3-react, and wagmi
  • Manual signer/provider plumbing
  • Additional dependency surface area
  • Mixed numeric paradigms (BigNumber vs native types)

Since wagmi already provides:

  • readContract / writeContract
  • Multicall support
  • Wallet + network state
  • Automatic signer resolution

And viem provides:

  • ABI encoding/decoding
  • Hex utilities
  • Native bigint-based numeric handling

Maintaining ethers and web3-react was redundant.

This refactor consolidates all Web3 logic under a single abstraction stack (wagmi + viem), reduces complexity, removes redundant layers, and simplifies long-term maintenance.

bsvalverde and others added 30 commits February 10, 2026 16:00
…transactionadder-hook

Partial viem migration
…recoverfundsfromproxy-hook

Partial viem migration
Comment thread apps/cowswap-frontend/src/modules/twap/hooks/useCancelTwapOrder.ts Outdated
Comment thread apps/cowswap-frontend/src/cowSdk.ts Outdated
@shoom3301
Copy link
Copy Markdown
Collaborator

@brunota20 token search doesn't work as expected, try to seach for "SHO" in Mainnet.
I think it's related to https://github.com/cowprotocol/cowswap/pull/7061/changes#r3040149007.

This PR:

image

https://dev.swap.cow.fi:

image

Comment thread libs/wallet/src/reown/consts.ts Outdated
Comment thread eslint.config.js
Comment thread eslint.config.js
@shoom3301
Copy link
Copy Markdown
Collaborator

@brunota20 there is also an issue with wallet name and icon displaying.

  • it doesn't resolve ENS name (you can try with my account 0xfb3c7eb936cAA12B5A884d612393969A557d4307)

This PR:
image

Prod:
image

Comment thread libs/ens/src/hooks/useENSName.ts Outdated
Comment thread libs/wallet/src/wagmi/updater.ts Outdated
Copy link
Copy Markdown
Collaborator

@shoom3301 shoom3301 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested the main scenarios, it works well!
Thanks a lot @bsvalverde and @brunota20 !

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants