Token Approvals
Before trading ERC-20 tokens on CoW Protocol, you must approve the protocol to spend your tokens. The SDK provides convenient methods to check and manage token approvals.Overview
ERC-20 tokens require explicit approval before a smart contract can transfer them on your behalf. CoW Protocol uses a Vault Relayer contract to handle token transfers during order settlement.You only need to approve tokens you’re selling. You don’t need approval for tokens you’re buying.
Checking Token Allowance
UsegetCowProtocolAllowance to check how much of a token the CoW Protocol can spend:
Method Signature
Parameters
tokenAddress- The ERC-20 token contract addressowner- The address of the token owner (your wallet)chainId- (Optional) Chain ID, uses SDK’s chain ID if not provided
Returns
Promise<bigint>- Current allowance amount in the token’s smallest unit
Example
Approving Tokens
UseapproveCowProtocol to approve the CoW Protocol to spend your tokens:
Method Signature
Parameters
tokenAddress- The ERC-20 token contract addressamount- The amount to approve (as bigint)chainId- (Optional) Chain ID, uses SDK’s chain ID if not providedsigner- (Optional) Custom signer, uses SDK’s signer if not provided
Returns
Promise<string>- Transaction hash of the approval transaction
Example
Smart Approval Flow
It’s best practice to check the current allowance before approving to avoid unnecessary transactions:Infinite Approval
You can approve the maximum possible amount to avoid repeated approval transactions:Complete Trading Flow with Approvals
Here’s a complete example that checks approval, approves if needed, and then creates an order:Approvals for Smart Contract Wallets
Smart contract wallets like Safe require special handling for approvals:For Safe and other smart contract wallets, you’ll need to propose the approval transaction through your wallet’s interface and collect the required signatures.
Revoking Approvals
To revoke an approval, set the allowance to 0:Implementation Details
Under the Hood
The SDK methods interact with these contracts:- getCowProtocolAllowance: Calls
allowance(owner, spender)on the ERC-20 token - approveCowProtocol: Calls
approve(spender, amount)on the ERC-20 token
spender is always the CoW Protocol Vault Relayer contract address for your chain.
From the Source Code
Common Issues and Solutions
Transaction Reverts
Problem: Approval transaction reverts. Solution:- Ensure you have enough ETH for gas
- Check that the token address is correct
- Verify you’re on the correct network
Approval Shows 0 After Transaction
Problem: Allowance still shows 0 after approving. Solution: Wait for the transaction to be confirmed before checking allowance.Order Fails Despite Approval
Problem: Order creation fails even with sufficient approval. Solution:- Verify you approved enough tokens (including fees and slippage)
- Check that your wallet has sufficient token balance
- Ensure the approval transaction was confirmed
Best Practices
- Check before approving: Always check current allowance first
- Approve sufficient amounts: Include slippage and fees in your approval amount
- Consider security: Use exact amounts instead of infinite approvals when possible
- Wait for confirmation: Always wait for approval transaction to confirm
- Handle errors gracefully: Implement proper error handling for approval failures
- Batch approvals: If trading multiple tokens, consider approving them all upfront
Next Steps
- Learn about Creating Swap Orders to use your approved tokens
- See Smart Contract Wallets for advanced approval scenarios
- Explore Order Management to track your trades