Skip to main content

Order Management

Track, monitor, and cancel orders using the CoW Protocol SDK.

Overview

After creating an order, you can:
  • Retrieve order details - Get full information about an order
  • Cancel off-chain - Free and fast soft cancellation
  • Cancel on-chain - Gas-required hard cancellation
All order management methods require an order UID (unique identifier) returned when creating an order.

Retrieving Order Details

Use getOrder to fetch complete information about an order:

Method Signature

Parameters

  • orderUid - The unique identifier of the order
  • chainId - (Optional) Chain ID, uses trader params if not provided

Returns

  • Promise<EnrichedOrder> - Full order details including status, amounts, and metadata

Example

Order Status Values

The status field can be one of:

EnrichedOrder Properties

Tracking Order Progress

Off-Chain Order Cancellation

Off-chain cancellation is the recommended way to cancel orders. It’s free, fast, and doesn’t require gas.

Method Signature

Parameters

  • orderUid - The unique identifier of the order to cancel
  • chainId - (Optional) Chain ID, uses trader params if not provided
  • signer - (Optional) Custom signer, uses trader params signer if not provided

Returns

  • Promise<boolean> - True if cancellation was successful

Example

How It Works

  1. Sign cancellation message - The SDK creates and signs a cancellation message using EIP-712
  2. Send to order book - The signed cancellation is sent to the CoW Protocol order book API
  3. Order removed - The order book marks the order as cancelled and stops including it in solutions
Off-chain cancellation is a “soft” cancel. While the order book will stop trying to fill the order, the order signature remains valid on-chain. For complete security, use on-chain cancellation.

On-Chain Order Cancellation

On-chain cancellation provides a hard guarantee that the order cannot be filled. It requires gas but is the most secure method.

Method Signature

Parameters

  • orderUid - The unique identifier of the order to cancel
  • chainId - (Optional) Chain ID, uses trader params if not provided
  • signer - (Optional) Custom signer, uses trader params signer if not provided

Returns

  • Promise<string> - Transaction hash of the cancellation

Example

How It Works

The SDK automatically detects the order type and uses the appropriate contract:
  • Regular orders: Calls invalidateOrder() on the Settlement contract
  • ETH-Flow orders: Calls invalidateOrder() on the EthFlow contract

Gas Costs

On-chain cancellation costs gas:

Comparing Cancellation Methods

Complete Example: Order Lifecycle

Here’s a complete example showing order creation, tracking, and cancellation:

Batch Order Monitoring

Monitor multiple orders efficiently:

Best Practices

  1. Always store order IDs: Save order UIDs for future reference
  2. Monitor important orders: Track order status for large trades
  3. Try off-chain first: Start with off-chain cancellation to save gas
  4. Handle errors gracefully: Orders might already be filled when you try to cancel
  5. Set reasonable expiration: Don’t set validFor too long if you might want to cancel
  6. Check status before operations: Verify order state before cancelling
  7. Use appropriate cancellation: Choose based on order value and security needs

Common Issues and Solutions

Order Not Found

Problem: getOrder throws “Order not found” error. Solution:
  • Verify the order UID is correct
  • Ensure the order has been created (wait a few seconds after posting)
  • Check you’re using the correct chain ID

Cancellation Fails

Problem: Off-chain cancellation returns false or throws error. Solution:
  • Check if the order is already filled or expired
  • Verify you’re using the same signer that created the order
  • Try on-chain cancellation as a fallback

Order Still Executes After Cancellation

Problem: Order filled despite cancellation. Solution:
  • This can happen with off-chain cancellation if there’s a race condition
  • Use on-chain cancellation for critical orders
  • Always wait for confirmation before assuming cancellation succeeded

Next Steps

Last modified on March 11, 2026