Overview
DEX (Decentralized Exchange) swaps execute on-chain through smart contracts. Unlike CEX swaps that use deposit addresses, DEX swaps require users to connect their wallet, sign transactions, and broadcast them directly to the blockchain.Best For: Users who want true decentralized swaps, keep custody of their funds, and interact directly with on-chain liquidity sources like Uniswap, Cowswap, and 1inch.
Supported Networks
DEX swaps are currently supported on the following networks:- EVM (Ethereum, BSC, Polygon, etc.)
- Solana
- SUI
- TRON
- TON
- Stellar
Key Characteristics
How It Works
DEX swaps follow this flow:Technical Flow Diagram
This diagram shows the complete integration flow with conditional logic:Integration Steps
Step 1: Get Supported Assets
Discover which tokens and networks are available for DEX swaps. Learn more about DEX tokens and network identifiers.Step 2: Get DEX Quote
Request a quote for the DEX swap using token IDs from/dexTokens:
tokenIdFrom: Source token_idfrom/dexTokensendpointtokenIdTo: Destination token_idfrom/dexTokensendpointamount: Amount to swap (float:1= 1 token)slippage(optional): Slippage percentage (e.g.,0.5for 0.5%)fromAddress(optional): Specific source address for the swaptoAddress(optional): Specific destination address for receiving tokens
Quote Response
The response is an array of quote options from different DEX aggregators, sorted by best rate (highest output first). Each quote object contains:Step 3: Check Approvals and Signatures
Before executing a swap, check what’s needed from the user:approvals: Array of on-chain approval transactions (may be empty)signatures: Array of signatures needed (may be empty)
Both Arrays Can Exist: You may receive both approvals AND signatures. Handle approvals first, then signatures.
Understanding Approvals
If theapprovals array is not empty, the user must approve the DEX to spend their tokens. See more in Step 4.
Understanding Signatures
Thesignatures array can contain two types:
1. SINGLE Type - Simple one-time signature: Action: User signs once, add to results, done.
2. CHAINED Type - Multi-step signature (currently only for Cowswap): Action: User signs, call /chainSignatures, repeat until isComplete: true.
See more in Step 5.
Step 4: Send Approval Transactions (if needed)
If theapprovals array is not empty, broadcast approval transactions:
Step 5: Process Signatures (if needed)
Handle signature requests from Step 3:- SINGLE: User signs once, done
- CHAINED: User signs → API call → User signs again → Repeat until complete
- Only keep the final signature from CHAINED sequences
Step 6: Check Allowance (if approvals were sent)
If you sent approval transactions in Step 4, verify they are confirmed on-chain:Step 7: Execute the Swap
Now execute the swap with any collected signatures:tokenIdFrom: Source token IDtokenIdTo: Destination token IDamount: Amount to swap (float)addressFrom: User’s wallet address (source)addressTo: Destination address for receiving tokensroute: Complete route object from quote response (quote.raw)swap: DEX identifier from quote (e.g., “zx” for 0x, “cs” for Cowswap)quoteId: Quote ID from quote responsesignatures: Array of signature objects from Step 5 (empty if none required)destinationTag: Memo/tag for chains that require it (empty string if not needed)deviceInfo: Device type - “web”, “ios”, “android”, or custom identifierisMobile: Boolean indicating if request is from mobile devicewalletInfo: Name of wallet being used (e.g., “MetaMask”, “Rabby Wallet”)slippage: Custom slippage tolerance (null to use default from quote)
order.houdiniId: Unique swap identifier for trackingorder.metadata.offChain: Boolean indicating if user transaction is neededorder.metadata.to: DEX router address (if offChain: false)order.metadata.data: Encoded swap call (if offChain: false)order.metadata.value: ETH value for native swaps (if offChain: false)
Broadcast Transaction and Confirm
After receiving the swap order, you need to:- Have the user broadcast the transaction (if
offChain: false) - Call
/dexConfirmTxto notify Houdini of the transaction hash
- On-Chain Swap (offChain: false)
- Off-Chain Swap (offChain: true)
User must broadcast the transaction, then confirm with Houdini:
Step 8: Track Swap Status
Monitor the swap progress:0= WAITING - Awaiting transaction1= CONFIRMING - Transaction submitted, waiting for confirmations2= EXCHANGING - Processing swap4= COMPLETED - Swap complete ✅6= FAILED - Swap failed ❌
Complete Example
For a complete, runnable Node.js example:DEX Swap Example
Complete DEX swap script with approval handling and wallet simulation
Next Steps
Private Swaps
Learn about CEX-based private swaps
Standard Swaps
Integrate fast single-hop CEX swaps
Order Lifecycle
Understand swap status progression
Error Handling
Handle errors and edge cases