Skip to main content

Basic Swap Example

This example demonstrates how to create a basic swap order using the CoW Protocol SDK. We’ll swap WETH for USDC on Sepolia testnet.

Prerequisites

  • Node.js installed
  • A wallet with some testnet ETH
  • An Ethereum provider (RPC endpoint)

Installation

Complete Example

Understanding the Code

1. Setup the Adapter

The adapter connects the SDK to your Ethereum provider:

2. Initialize the Trading SDK

3. Get a Quote

Request a quote for the swap:

4. Post the Order

Quote Results

The quote contains important information:

Error Handling

Always wrap SDK calls in try-catch blocks:

Next Steps

Last modified on March 11, 2026