> ## Documentation Index
> Fetch the complete documentation index at: https://docs.krokoswap.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Universal Router

> Unified swap execution contract ABI and usage

# Universal Router Contract

The Universal Router executes swaps across V2 and V3 pools via an encoded command interface. In practice, you do not need to encode commands yourself — the [Swap API](/api/swap) generates the calldata for you.

For the concept overview, see [Universal Router Concepts](/concepts/universal-router).

## Key Functions

### execute

Executes a sequence of commands in order.

```solidity theme={null}
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 |

<Warning>
  You typically do not call `execute()` directly. Use the [Swap API](/api/swap) to generate the `{ to, data, value }` object, then send it as a transaction.
</Warning>

## Command Types

| 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 |

## Usage Pattern

The recommended pattern is to use the Swap API to generate calldata:

```typescript theme={null}
// 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 Handling

Common revert reasons:

| 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 |

## ABI

```json theme={null}
[
  "function execute(bytes calldata commands, bytes[] calldata inputs, uint256 deadline) external payable"
]
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.