OrderSigningUtils
EIP-712 order signing and cancellation utilities for CoW ProtocolOverview
TheOrderSigningUtils class provides static methods for signing CoW Protocol orders and cancellations using EIP-712 standards. It supports multiple signing schemes including standard EOA wallets and smart contract wallets.
Installation
Usage
All methods are static and can be called directly on the class.Methods
signOrder
Signs an order using EIP-712 typed data signing.Example
signOrderCancellation
Signs a cancellation for a single order.Example
signOrderCancellations
Signs a cancellation for multiple orders at once.More gas-efficient than signing cancellations individually when cancelling multiple orders.
Example
getDomain
Retrieves the EIP-712 typed domain data for a given chain.Example
getDomainSeparator
Returns the domain separator hash for a given chain.Example
generateOrderId
Creates a deterministic order ID from order data and owner address.Example
getEIP712Types
Returns the EIP-712 type definitions for CoW Protocol orders.Example
getEip1271Signature
Encodes an order and ECDSA signature for EIP-1271 smart contract verification.Useful for smart contract wallets that implement EIP-1271 signature verification.
Example
encodeUnsignedOrder
Encodes an unsigned order for hashing.Example
Signing Schemes
EIP-712 (Default)
Standard EIP-712 typed data signing. Provides the best user experience with human-readable signing prompts.EthSign (EIP-191)
Legacy signing method. Automatically used as fallback if EIP-712 is not supported by the wallet.Pre-sign
For smart contracts that cannot sign directly. Orders are approved on-chain viasetPreSignature().
EIP-1271
For smart contract wallets implementing the EIP-1271 signature verification standard.Integration Examples
With OrderBookApi
With TradingSdk
Cancelling Orders
Error Handling
Best Practices
- Always verify chain ID - Ensure the chainId matches the network you’re operating on. Incorrect chain IDs produce invalid signatures.
- Set global adapter - Call
setGlobalAdapter()before usingOrderSigningUtilsto ensure the correct provider is available. - Use typed data (EIP-712) - Prefer EIP-712 signing for the best security and user experience. The SDK handles fallback automatically.
- Batch cancellations - Use
signOrderCancellations()instead of multiplesignOrderCancellation()calls for efficiency. - Handle rejections - Always handle the case where users reject signature requests in their wallet.
See Also
- TradingSdk - High-level trading interface with built-in signing
- OrderBookApi - Order submission and management
- MetadataApi - Order metadata utilities
- EIP-712 Specification - Typed structured data hashing and signing
- EIP-1271 Specification - Standard signature validation for contracts