Execute Swap
Prerequisites
Basic Swap
const pair = await sdk.Pair.getPair(pairAddress);
// Swap 1 SUI for USDC
const tx = await sdk.Swap.prepareSwap(pair, {
amount: 1000000000n, // 1 SUI (9 decimals)
xtoy: true, // SUI (X) to USDC (Y)
recipient: userAddress // Optional, defaults to sender
});
await sdk.fullClient.signAndExecuteTransaction({
transaction: tx,
signer: keypair
});Swap Parameters
Swap Directions
X to Y Swap
Y to X Swap
Understanding Token Order
Complete Swap Example
Swap with Custom Recipient
How Swaps Work
Common Patterns
Swap Exact Input
Check Balance First
Error Handling
Gas Optimization
Related Topics
Last updated