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

# 7k Protocol Swap

> Learn how to swap tokens using 7k Protocol integration

Execute token swaps on Sui using the 7K Protocol for aggregation, ensuring slippage protection.

## Usage

```javascript theme={null}
// Swap token use symbol
const result = await agent.swap({
  fromToken: "SUI";
  toToken: "USDC";
  inputAmount: 1;
  slippage: 0.01; // 1%
})

// Swap token use address
const result = await agent.swap({
  fromToken: "SUI";
  toToken: "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC";
  inputAmount: 1;
  slippage: 0.01; // 1%
})
```

## Parameters

| Parameter   | Type   | Required | Description                                    |
| ----------- | ------ | -------- | ---------------------------------------------- |
| fromToken   | string | Yes      | Address or symbol of the input token           |
| toToken     | string | Yes      | Address or symbol of the output token          |
| inputAmount | number | Yes      | Amount of the input token to swap              |
| slippage    | number | No       | Maximum allowable slippage (e.g., 0.01 for 1%) |

## Example Prompts

### Natural Language Prompts

```javascript theme={null}
"Swap 1 SUI for USDC"

"Exchange 100 USDC for SUI with 1% slippage"

"Convert 50 USDT to SUI"
```

### LangChain Tool Prompts

```javascript theme={null}
// Swap Sui for USDC
{
 "fromToken": "SUI";
 "toToken": "USDC";
 "inputAmount": 1;
 "slippage": 0.01; // 1%
}

// Swap Sui for USDC
{
 "fromToken": "SUI";
 "toToken": "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC";
 "inputAmount": 1;
 "slippage": 0.01; // 1%
}
```

## Example Implementation

```javascript theme={null}
import { SuiAgentKit } from "sui-agent-kit";

async function executeSwaps(agent: SuiAgentKit) {
  try {
    const res = await agent.swap({
      fromToken: "SUI",
      toToken: "USDC",
      inputAmount: 100,
      slippage: 0.01, // 1%
    });
    
    console.log("Swap result:", res);
  } catch (error) {
    console.error("Swap failed:", error);
  }
}
```

## Implementation Details

* Uses 7k Protocol for best prices
* Dynamic compute unit limits
* Auto-calculated priority fees
* Direct route optimization

## Error Handling

```javascript theme={null}
try {
  const res = await agent.swap({
    fromToken: "SUI",
    toToken: "USDC",
    inputAmount: 100,
    slippage: 0.01, // 1%
  });
} catch (error) {
  if (error.message.includes("Insufficient balance")) {
    // Handle insufficient balance
  } else {
    // Handle other transaction failures
  }
}
```

## Best Practices

1. Slippage Management

* Use appropriate slippage for token
* Consider market volatility
* Monitor price impact
* Handle failed transactions

2. Amount Calculation

* Account for token decimals
* Check minimum amounts
* Consider fees
* Verify available balance

3. Error Handling

* Implement retries
* Monitor transaction status
* Handle timeouts
* Verify swap results

4. Performance

* Use direct routes when possible
* Set appropriate compute limits
* Monitor network conditions
* Consider priority fees

## Response Format

```
// Successful response
{
  status: "success",
  result: {
    tx_hash: "5JvBtQveYFsZFYxXMfSxYzUJgzGfyRgkH9YuZxpvuR9Y",
    tx_status: "success",
  },
}

// Error response
{
  status: "error",
  message: "Error message here",
  code: "ERROR_CODE"
}
```

## Related Functions

* get\_holding: Check token balances
* transfer: Transfer token.
