Swap
Execute token swaps on Ferra pools.
Quick Start
// Simple swap: 1 SUI -> USDC
const swapParams = {
pool_id: '0x...',
coinTypeA: '0x2::sui::SUI',
coinTypeB: '0x...::usdc::USDC',
a2b: true, // SUI -> USDC
by_amount_in: true, // Fix input amount
amount: '1000000000', // 1 SUI
amount_limit: '990000', // Min 990 USDC (1% slippage)
}
const tx = await sdk.Swap.createSwapTransactionPayload(swapParams)
const result = await sdk.fullClient.signAndExecuteTransaction({
transaction: tx,
signer: keypair
})Swap Parameters
Parameter
Type
Description
pool_id
string
Pool object ID
coinTypeA
string
First token type
coinTypeB
string
Second token type
a2b
boolean
Direction (true: A→B, false: B→A)
by_amount_in
boolean
Fix input (true) or output (false)
amount
string
Fixed amount
amount_limit
string
Slippage limit
swap_partner
string
Optional partner for fees
Swap Directions
Swap A to B
Swap B to A
Fix Output Amount
Get exactly the amount you want:
Calculate Slippage
Gas Optimization (SUI)
Optimize gas when swapping SUI:
Partner Swaps
Route fees to partners:
Advanced Usage
Manual Coin Management
Batch Swaps
Complete Example
Error Handling
Important Notes
Always use
amount_limitfor slippage protectionSDK automatically handles coin selection
Excess coins are returned to sender
Partner swaps share fees with partners
Gas optimization available for SUI swaps
Last updated