Swap API (Imperative)
Execute token swaps with full control over transaction execution
Swap API (Imperative)
The Swap API provides imperative swaps, giving traders full control over route planning and transaction execution. Unlike intent-based swaps, imperative swaps return a complete transaction that you sign and submit.
Imperative vs Declarative: Imperative swaps give you the exact route before signing. For hands-off trading with potentially better execution, see Intent API.
Access
Methods
getQuote
Get a quote for a swap without creating a transaction.
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 |
slippageBps | number | No | Slippage tolerance (default: 50 = 0.5%) |
Returns: SwapQuote
createSwap
Create a swap transaction ready for signing.
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 |
slippageBps | number | No | Slippage tolerance in basis points |
userPublicKey | string | Yes | User's wallet public key |
wrapUnwrapSol | boolean | No | Auto wrap/unwrap native SOL |
priorityFee | PriorityFee | No | Transaction priority fee |
Priority Fee Types:
Returns: SwapResponse
getSwapInstructions
Get raw swap instructions for custom transaction composition.
Use getSwapInstructions when you need to combine the swap with other instructions in a single transaction.