Skip to main content

Wagmi Integration

This guide demonstrates how to integrate the CoW Protocol SDK with Wagmi and Viem for a production-ready React application with proper wallet management.

Why Wagmi?

Wagmi provides:
  • Easy wallet connection with multiple providers
  • Automatic account and network management
  • React hooks for blockchain interactions
  • TypeScript support
  • Better developer experience

Installation

Setup Wagmi

Configure Wagmi with your app settings:

Setup CoW SDK

Create a Trading SDK instance:

Bind SDK to Wagmi Hook

Create a custom hook to sync the SDK with Wagmi’s wallet state:

Swap Component

Create a swap form that uses Wagmi hooks:

Main App Component

Main Entry Point

Token Approval with Wagmi

Handle token approvals using the SDK:

Key Benefits

  1. Automatic Network Switching: Wagmi handles network changes automatically
  2. Multi-Wallet Support: Users can connect with various wallets
  3. TypeScript Safety: Full type safety with Viem
  4. React Query Integration: Efficient data fetching and caching
  5. Better UX: Professional wallet connection UI

Connect Wallet Button

Add a proper wallet connection button:

Network Switching

Handle network switching gracefully:

Next Steps

Last modified on March 11, 2026