// 1. Get calldata from Swap API
const response = await fetch('/swap-api/api/v1/swap', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
tokenIn: '0x...',
tokenOut: '0x...',
amountIn: '1000000000000000000',
tradeType: 0,
slippage: 0.5,
recipient: userAddress,
deadline: 1200
})
});
const swapData = await response.json();
// 2. Send the transaction directly
const tx = await signer.sendTransaction({
to: swapData.to, // Universal Router address
data: swapData.data, // Encoded execute() calldata
value: swapData.value // Native KAS value (0 for ERC-20 swaps)
});