Intent API (Declarative)
Lightweight intent-based swaps with JIT routing for best execution
Intent API (Declarative)
The Intent API provides declarative swaps that defer route calculation to execution time. This approach offers less slippage, greater sandwich protection, and JIT (Just-In-Time) routing for best execution.
Declarative vs Imperative: Intent swaps express what you want to trade, and DFlow's infrastructure handles optimal execution. For full control over the route, see Swap API.
Access
Methods
getIntentQuote
Get a quote for an intent swap.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
inputMint | string | Yes | Input token mint address |
outputMint | string | Yes | Output token mint address |
amount | number | Yes | Amount in smallest units |
mode | 'ExactIn' | 'ExactOut' | Yes | Trade mode |
Mode Types:
| Mode | Description |
|---|---|
ExactIn | Specify exact input amount, output may vary |
ExactOut | Specify exact output amount, input may vary |
submitIntent
Submit an intent swap for execution.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
inputMint | string | Yes | Input token mint address |
outputMint | string | Yes | Output token mint address |
amount | number | Yes | Amount in smallest units |
mode | 'ExactIn' | 'ExactOut' | Yes | Trade mode |
slippageBps | number | No | Max slippage tolerance |
userPublicKey | string | Yes | User's wallet public key |
Returns: IntentResponse
Why Use Intents?
Benefits of Declarative Swaps
- Better Execution: Route is calculated at execution time, not quote time
- Sandwich Protection: Harder for MEV bots to extract value
- Less Slippage: JIT routing finds optimal paths dynamically
- Simpler UX: One transaction, no route complexity exposed
When to Use Intents
- ✅ Standard trading flows
- ✅ Mobile/wallet integrations
- ✅ When you trust DFlow's routing
- ✅ For time-sensitive trades
When to Use Imperative Swaps
- ✅ When you need exact route preview
- ✅ For auditing/compliance requirements
- ✅ Custom transaction composition
- ✅ When combining with other instructions
Examples
ExactIn Intent
Specify how much you want to spend:
ExactOut Intent
Specify how many tokens you want to receive:
Compare Quote vs Imperative
Intent quotes may show slightly better rates because the actual route is optimized at execution time.