Grant Application: Migration of CoW Swap Frontend to Viem & Wagmi

Author(s)

@bleu @bsvalverde @ribeirojose

Experiences and Qualifications

bleu collaborates with companies and DAOs as a web3 technology and user experience partner. We are the team behind several core CoW Protocol developer tools and have a deep understanding of the codebase.

Our track record with CoW:

  • [CoW] Framework Agnostic SDK: We re-architected the CoW SDK to support Viem natively, abstracting away the Ethers.js dependency. This grant operationalizes that work.
  • [CoW] Playground Offline Mode: (Recently Approved) Created the local dev environment with offline signing for backend engineers.
  • [CoW] Hook dApps: Integrated Hook dApps and developed the cow-shed module.

Grant Description

The CoW Swap frontend currently relies on Web3React, an aging library that is largely unmaintained, and initializes the CoW SDK using the legacy Ethers.js adapter. This creates technical debt, mobile connection instability, and requires workarounds to support modern features like EIP-6963 (Multi-Injected Providers).

In addition, the current wallet and frontend code paths rely heavily on Ethers.js v5 and TypeChain-generated ABIs.

The current web3-react stack presents growing risks to the Protocol:

  • The library is unmaintained;
  • Existing EIP-6963 support is a hacky Web3React workaround and can still cause wallet conflicts.
  • The current wallet integration is brittle; modern libraries like Reown offer superior reliability.
  • Integrating new chains or wallets requires complex custom code rather than simple configuration.
  • Ethers.js- and TypeChain-based patterns make the code harder to modernize and maintain compared to a Viem-based approach.

As part of this grant, we will:

  • Remove Web3React entirely from the frontend,
  • Migrate SDK and wallet flows to Viem + Wagmi,
  • Maintain full support for all existing wallet connectors: EIP-6963, injected browser extensions (window.ethereum, including mobile web3 browsers), WalletConnect, Coinbase Wallet, and Gnosis Safe, and
  • Remove Ethers.js and TypeChain (ethers-v5 targets) from the frontend wallet/connection layer, migrating to viem-native primitives.

We will use CoW Swap’s existing LaunchDarkly feature flags to run the old and new stacks in parallel, allowing a gradual rollout and instant rollback if any issues are detected.

Key Dependencies to Update

As part of this migration, we will also update the Safe SDK stack to their latest major versions, which provide Viem-native support and drop Ethers.js:

Package Current Target Note
@safe-global/api-kit ^1.3.0 ^4.0.1 New API surface
@safe-global/protocol-kit ^1.2.0 ^6.1.2 Viem-native support
@safe-global/safe-core-sdk-types ^2.2.0 ^5.1.0 Updated type definitions
@safe-global/safe-ethers-lib ^1.9.4 Removed Replaced by Viem / Safe tooling

Impact

  • Fixing wallet connection flakiness directly improves the “Connect Wallet” conversion rate, ensuring fewer users drop off before trading.

  • Native EIP-6963 support means users can choose between injected wallets in the UI without disabling browser extensions. This removes reliance on the previous custom Web3React workaround.

  • Offloads complex connection logic to maintained libraries (Wagmi), reducing the maintenance burden on the CoW core team and easing onboarding for new developers.

  • Operationalizes the DAO’s previous investment in the Framework Agnostic SDK.

  • Improved frontend stability and maintainability and cleaner abstractions for future development, easing onboarding to new devs.

Type of Grant

Milestone-based grant

Milestones

Milestone Title Due date (*) Funding request
Milestone 1 Core Architecture & SDK Integration Week 1-2 4,000 xDAI
Milestone 2 Wallet Connection & EIP-6963 Week 2-3 4,000 xDAI
Milestone 3 Safe Wallet Integration Week 4 3,100 xDAI
Milestone 4 Chain Selection & Network Handling Week 5-6 5,000 xDAI
Milestone 5 QA, Testing & Staged Rollout Week 7-8 5,000 xDAI
Milestone 6 Frontend Route Migration Week 9 3,100 xDAI
Milestone 7 Cleanup & Documentation Week 9–10 4,000 xDAI

(*) Weeks after acceptance/commencement. Some milestones overlap; overall completion is expected within 10 weeks.

M1: Core Architecture & SDK Integration

Tasks:

  • Install Viem, Wagmi, and Reown.
  • Configure the new provider architecture behind an existing LaunchDarkly feature flag (reusing CoW Swap’s current flag infrastructure).
  • Switch CoW SDK to use ViemAdapter (leveraging our previous grant work), while keeping EthersV5Adapter available as a fallback behind the flag.
  • Implement a compatibility hook for legacy components that provides wallet and chain state from a single interface. The hook will internally decide whether to fetch data from the old or new stack based on the feature flag, allowing all components to use a consistent API during the gradual migration.

Deliverables:

  • Functional app built with the new stack wired and hidden behind a LaunchDarkly feature flag.
  • Short architecture documentation describing the new connection layer, feature-flag wiring, and SDK integration (ViemAdapter vs Ethers adapter).

M2: Wallet Connection & EIP-6963

Tasks:

  • Implement Reown (AppKit) connection flows.
  • Replace custom EIP-6963 support with native Wagmi support (fixing multi-injected wallet conflicts).
  • Migrate Trezor connection logic to Wagmi/Reown (or adapter) while preserving feature parity (account selection, signing).
  • Implement robust connect/disconnect handling for all supported wallets.
  • Keep the existing Web3React connection system running in parallel behind the feature flag for safe comparison and fallback.

Note on Trezor verification: Trezor hardware wallet validation requires CoW team assistance for device testing. We will coordinate testing sessions with team members who have Trezor devices to validate account selection, message signing, and order signing flows.

Deliverables:

  • All existing wallet connectors (EIP-6963, injected extensions including mobile, WalletConnect, Coinbase, and Gnosis Safe) connecting via Wagmi/Reown;
  • No remaining custom EIP-6963 patches or Web3React-based shims;

M3: Safe Wallet Integration

Tasks:

  • Upgrade the Safe SDK stack (@safe-global/api-kit, @safe-global/protocol-kit, @safe-global/safe-core-sdk-types) to the target versions listed in Key Dependencies to Update, and remove @safe-global/safe-ethers-lib.
  • Integrate Safe Apps SDK v2
  • Implement Safe detection (Safe iframe and Safe via WalletConnect).
  • Ensure bundle transaction support (approval + presign flows) for Safe.
  • Retrieve Safe metadata such as owners, chain, and context for UX.

Deliverables:

  • Parity with existing Safe functionality.
  • Tested flows for Safe connection, signing, and bundled transactions;

M4: Chain Selection & Network Handling

Tasks:

  • Migrate chain switching logic for all 11 supported networks to Wagmi/Viem.
  • Handle “Unsupported Network” states gracefully in the UI.
  • Improve RPC error messages and auto-switch flows where appropriate.

Deliverables:

  • Robust network switching via Wagmi hooks, including error handling.
  • Frontend reading chain state exclusively from the new connection layer when enabled.

M5: QA, Testing & Staged Rollout

Tasks:

  • Introduce or significantly expand automated end-to-end tests (e.g. Cypress/Playwright) for wallet connect/disconnect, chain switching, and basic trading flows, given current limited automated coverage.
  • Test mobile WalletConnect on iOS and Android (Reown AppKit).
  • Enable the feature flag on Staging and run both stacks in parallel;
  • Monitor logs, metrics, and user feedback for regressions – in coordination with the CoW Swap frontend team.

M6: Frontend Route Migration

Tasks:

  • Update wallet state usage across critical routes:
    • Swap widget
    • Order history
    • Balances
    • Limit Orders
    • TWAP and related advanced order flows
  • Ensure components no longer depend directly on Web3React hooks, relying instead on Wagmi/Viem (or the compatibility shim where absolutely necessary).
  • Fix any remaining ethers-based patterns in these frontend routes as they relate to wallet/connection logic.

Deliverables:

  • All targeted routes functioning with the new wallet/chain state.
  • Visual and behavioral parity verified for these routes.
  • No direct Web3React usage in the frontend routes covered by this milestone.

M7: Cleanup & Documentation

Tasks:

  • Delete Web3React code (47+ files and related helpers).
  • Remove @web3-react/* packages from package.json.
  • Remove Ethers.js-based wallet/connection usage from the frontend path (including the EthersV5Adapter code path for the SDK).
  • Update TypeChain configuration and generated types so that frontend contract interactions use Viem-compatible typings/ABIs instead of ethers-v5 targets.
  • Migrate remaining BigNumber-based wallet/frontend code to bigint/Viem primitives;
  • Remove the migration feature flag once production is stable and the new stack is validated.

Deliverables:

  • Clean codebase with:
    • Zero Web3React imports or dependencies.
    • Zero EthersV5Adapter usage in the frontend.
    • No Ethers.js usage in the wallet/frontend path covered by this grant.
  • TypeChain removed, using SDK instead.
  • A short architecture/migration note (ADR-style) explaining key decisions for future maintainers.

Length

(Suggested) Start Date: January 5th
Expected Completion: Up to 10 weeks from commencement

Funding Request

Total Funding: 28,200 xDAI

Payment Information

Gnosis Chain Address: 0x554866e3654E8485928334e7F91B5AfC37D18e04

Terms and Conditions

By submitting this grant application, I acknowledge and agree to be bound by the CoW DAO Participation Agreement and the CoW DAO Grant Agreement Terms.

2 Likes

Thank you @bleu !

I’ve reviewed the application, and it looks good to me!

I’m ready to help as much as possible with that initiative.

2 Likes

Thanks for the super prompt follow-up on reviewing of this grant :folded_hands: On the provision that @shoom3301 is happy to act as reviewer, I think we are in a good position pretty fast on this grant.

I’d be very happy to see stacks of tech debt cut through. I signal my support for this grant, and if no opposition, would suggest that @bleu move this to snapshot on Monday 15th December (avoid over weekend voting).

mfw.

3 Likes

Thank you for your proposal @bleu, and thank you @shoom3301 for the application review!

I signal my support for this proposal and I look forward to seeing move forward.

2 Likes

Thanks for the feedback! Posted to snapshot here!

Snapshot was approved! Thanks grants committee for your trust again into our work!

We’ll start the development on day 19th on January and will update our progress into this forum post.

The first milestone, focused on setting the groundwork for the migration, is currently in review. Work on the next milestone, implementing wallet connection via Wagmi/Viem, is in progress and will follow once this review is complete.

The first milestone has been reviewed and updated with all required adjustments. At the same time, progress has been made on milestones 2 and 4 (wallet connection and chain exchange), which are planned to be sent for review early next week.

1 Like

@bleu hi!

FYI

About M3: looks like the most part was made via this PR, check it out, please, it’s been just merged into develop.

Also there is a yarn → pnpm migration in the develop branch.

You should better merge it into your local branch to get rid of future conflicts.

1 Like

Hi @bleu Quick update on this grant: Milestone 1 has now been paid.

As we are migrating the Grants Treasury Safe from Gnosis Chain to Ethereum mainnet, for the upcoming milestones of this grant, payments will be made on Ethereum. If the provided address for payments is a Safe, please make sure it is deployed on Ethereum and that the signer configuration is up to date. If you’d prefer to receive future payments at a different address, feel free to share an alternative one.

2 Likes

The PR for Milestones 2 and 4 is now in review. There was a small hiccup due to some repo updates, but it’s resolved.

Milestone 3 should be quick due to the updates you mentioned, and Milestone 5 is planned to be started later this week.

1 Like

During implementation, web3-react and wagmi did not behave as expected when used together. While the initial agreement was to deliver the work in incremental stages, further investigation showed that making both libraries coexist would require a disproportionate amount of time and effort.

After discussion with the Cow FE team, we decided to prioritize replacing the library instead. This results in a single final deliverable rather than the originally planned incremental ones, but allows time and resources to be used more effectively while reducing overall complexity.

1 Like

The removal of the old libraries is progressing well and is expected to continue over the next week.

2 Likes

The old libraries have been removed. We’re fixing a few issues that came up and running tests before submitting the final PR.

1 Like

Hi there!
I can confirm that the 1st and 2nd milestones are ready. I’ve been able to test the basic Reown integration.

Other functionalities are not ready for testing, so we are waiting for the issues that @bleu has’ mentioned to be fixed.

For visibility:

1 Like