Core
Universal Router
Unified swap execution contract ABI and usage
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Unified swap execution contract ABI and usage
function execute(
bytes calldata commands,
bytes[] calldata inputs,
uint256 deadline
) external payable;
| Parameter | Type | Description |
|---|---|---|
commands | bytes | Sequence of command codes (1 byte each) |
inputs | bytes[] | ABI-encoded parameters for each command |
deadline | uint256 | Unix timestamp after which the transaction reverts |
execute() directly. Use the Swap API to generate the { to, data, value } object, then send it as a transaction.| Command | Code | Description |
|---|---|---|
V2_SWAP_EXACT_IN | 0x00 | V2 swap with exact input amount |
V2_SWAP_EXACT_OUT | 0x01 | V2 swap with exact output amount |
V3_SWAP_EXACT_IN | 0x02 | V3 swap with exact input amount |
V3_SWAP_EXACT_OUT | 0x03 | V3 swap with exact output amount |
WRAP_ETH | 0x0b | Wrap native KAS to WKAS |
UNWRAP_WETH | 0x0c | Unwrap WKAS to native KAS |
PERMIT2_PERMIT | 0x0a | Execute a Permit2 signature-based permit |
TRANSFER | 0x04 | Transfer tokens |
// 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)
});
| Error | Cause | Solution |
|---|---|---|
EXPIRED | Transaction deadline exceeded | Use a longer deadline or submit faster |
V3_INVALID_AMOUNT_OUT | Output below minAmountOut | Increase slippage tolerance |
TRANSFER_FROM_FAILED | Insufficient approval or balance | Check Permit2 approval and token balance |
INSUFFICIENT_ETH | Not enough native KAS sent | Ensure value matches the required amount |
[
"function execute(bytes calldata commands, bytes[] calldata inputs, uint256 deadline) external payable"
]