CoW Protocol supports multiple signing schemes to accommodate different wallet types and use cases. Understanding these schemes is crucial for implementing order signing in your application.
EIP-712 is the preferred signing scheme. It provides structured, human-readable data to wallets, making signatures safer and more transparent for users.
// The SDK tries EIP-712 first, then falls back to ETHSIGNconst result = await OrderSigningUtils.signOrder( order, chainId, signer)// result.signingScheme could be:// - EcdsaSigningScheme.EIP712 (preferred)// - EcdsaSigningScheme.ETHSIGN (fallback)
Limitations of ETHSIGN:
Signs a raw hash without context
Wallet displays cryptic hex strings
Less secure user experience
Being phased out by modern wallets
Use EIP-712 whenever possible. ETHSIGN is primarily for backward compatibility.
Instead of an ECDSA signature, the order includes the contract address. The settlement contract calls isValidSignature() on the wallet contract to verify the order.
Copy
Ask AI
// For smart contract wallets, you typically:// 1. Create the order// 2. Get the order hash// 3. Have the contract sign/approve it// 4. Submit with EIP1271 schemeconst order = { // ... order parameters}// The smart contract wallet must implement EIP-1271interface EIP1271 { function isValidSignature( bytes32 hash, bytes memory signature ) external view returns (bytes4 magicValue);}
import { getGlobalAdapter } from '@cowprotocol/cow-sdk'// Get the settlement contractconst settlementContract = getContract( SETTLEMENT_CONTRACT_ADDRESS, SETTLEMENT_ABI)// Compute the order UIDconst orderUid = computeOrderUid( domain, order, ownerAddress)// Pre-sign the order on-chainconst tx = await settlementContract.setPreSignature( orderUid, true // signed = true)await tx.wait()// Now submit the order with PRESIGN schemeconst orderId = await orderBookApi.sendOrder({ ...order, from: ownerAddress, signingScheme: SigningScheme.PRESIGN, signature: '0x', // Empty signature for presign})
type EcdsaSigningScheme = SigningScheme.EIP712 | SigningScheme.ETHSIGNinterface EcdsaSignature { scheme: EcdsaSigningScheme data: SignatureLike // r, s, v components}
The SDK automatically handles the details:
Copy
Ask AI
// This returns an ECDSA signature (EIP712 or ETHSIGN)const { signature, signingScheme } = await OrderSigningUtils.signOrder( order, chainId, signer)// The signature contains the full ECDSA signature data// The signingScheme indicates which method was used