# Swap

Here are 3 cases of swapping in Pangea's pool via router :

### 1. ERC20 --> ERC20&#x20;

* Before the swap request, you need to make an approve request to the router for the input token.

```typescript
poolRouter.exactInputSingle({
          tokenIn: tokenInAddress, // input token address
          amountIn: BigNumber.from(amountIn), // amount of input token to swap
          amountOutMinimum: BigNumber.from(amountOutMinimum), // slippage
          pool: PoolAddress, // pool address
          to: recipient,     // recipient address
          unwrap: false      // always "false" for erc20 tokens
        });
```

### 2. ERC20 --> KLAY

* Before the swap request, you need to make an approve request to the router for the input token.

```typescript
poolRouter.exactInputSingle({
          tokenIn: tokenInAddress, // input token address
          amountIn: BigNumber.from(amountIn), // amount of input token to swap
          amountOutMinimum: BigNumber.from(amountOutMinimum), // slippage
          pool: PoolAddress, // pool address
          to: recipient,     // recipient address
          unwrap: true      // always "false" for erc20 tokens
        });
```

### 3. KLAY --> ERC20

```typescript
poolRouter.exactInputSingle({
          // if input token is KLAY, set token address to 0 address
          tokenIn: "0x0000000000000000000000000000000000000000", 
          amountIn: BigNumber.from(amountIn),
          amountOutMinimum: BigNumber.from(amountOutMinimum),
          pool: PoolAddress,
          to: recipient,
          unwrap: false
        }, {
           // amount of KLAY to sent should be input like below
           value: BigNumber.from(amountIn)
        });
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://pangeaswap.gitbook.io/pangeaswap/en/developers/interacting-with-the-protocol/swap.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
