Smart Contract Wallets
Smart contract wallets (like Safe/Gnosis Safe) require a different signing method than regular EOA (Externally Owned Account) wallets. The SDK supports smart contract wallets using thePRESIGN signing scheme.
Overview
Smart contract wallets cannot sign EIP-712 messages directly. Instead, they use on-chain signatures through thePRESIGN method:
- Create an order with
SigningScheme.PRESIGN - Get a pre-sign transaction from the SDK
- Execute the transaction to “sign” the order on-chain
PRESIGN is more gas-efficient for smart contract wallets compared to EIP-1271 signatures.
The PRESIGN Signing Scheme
When you useSigningScheme.PRESIGN, the SDK creates an order in a “pre-sign” state. The order is only valid after you execute an on-chain transaction that registers your approval.
How it Works
- Create order with PRESIGN scheme - The order is created in the order book with a special “pre-sign” status
- Get pre-sign transaction - Use
getPreSignTransactionto get the transaction data - Execute transaction - Send the transaction from your smart contract wallet
- Order becomes valid - Once the transaction is confirmed, the order is ready for execution
Creating Swap Orders with Smart Contract Wallets
Example
Creating Limit Orders with Smart Contract Wallets
Example
Getting Pre-Sign Quotes
For more accurate gas estimation, specify the signing scheme when getting quotes:The getPreSignTransaction Method
ThegetPreSignTransaction method returns transaction parameters ready to be executed.
Parameters
orderId- The unique identifier of the order to signaccount- The smart contract wallet address
Returns
ATransactionParams object with:
to- The contract address (Settlement contract)data- The encoded function callgasLimit- Estimated gas limitvalue- ETH value to send (usually ‘0’)
Implementation Details
The method callssetPreSignature(orderId, true) on the CoW Protocol Settlement contract:
Executing Pre-Sign Transactions
With Safe SDK
With Viem Wallet Client
Gas Considerations
PRESIGN orders require an on-chain transaction, which costs gas:- Gas cost: ~50,000-100,000 gas depending on the wallet implementation
- When to use: Best for larger orders where gas cost is negligible compared to order value
- Alternative: For small orders, consider using an EOA wallet instead
The pre-sign transaction gas cost is separate from the order execution cost. The execution cost is covered by the protocol’s fee mechanism.
Common Issues and Solutions
Order Not Found
Problem: The order hasn’t been created yet or the order ID is incorrect. Solution: Ensure you wait forpostSwapOrder or postLimitOrder to complete before calling getPreSignTransaction.
Insufficient Allowance
Problem: The smart contract wallet hasn’t approved tokens. Solution: Approve tokens before creating orders (see Token Approvals guide).Transaction Reverts
Problem: The pre-sign transaction reverts on-chain. Solution:- Verify the order ID is correct
- Ensure the wallet has enough ETH for gas
- Check that you’re using the correct chain ID
Best Practices
- Always specify the owner: For limit orders, explicitly set the
ownerparameter - Get quotes with PRESIGN: Include the signing scheme in quote requests for accurate estimates
- Wait for confirmation: Ensure the pre-sign transaction is confirmed before expecting order execution
- Handle transaction errors: Implement proper error handling for the on-chain transaction
- Check order status: Verify the order status after signing to ensure it’s ready
Next Steps
- Learn about Token Approvals for smart contract wallets
- See Order Management to track pre-signed orders
- Explore Creating Swap Orders for basic concepts