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

# swapToken

> Prompt the user to swap tokens

Prompts the user to swap tokens through the Farcaster client's built-in swap interface.

## Usage

```ts theme={"system"}
import { sdk } from '@farcaster/miniapp-sdk'

await sdk.actions.swapToken({
  sellToken: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', // USDC
  buyToken: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',  // WETH
  sellAmount: '1000000'
})
```

## Parameters

### sellToken (optional)

* **Type:** `string`

The contract address of the token to sell.

### buyToken (optional)

* **Type:** `string`

The contract address of the token to buy.

### sellAmount (optional)

* **Type:** `string`

Sell token amount, as numeric string

## Return Value

```ts theme={"system"}
type SwapTokenDetails = {
  /**
   * Array of tx identifiers in order of execution.
   * Some swaps will have both an approval and swap tx.
   */
  transactions: `0x${string}`[];
};

type SwapTokenErrorDetails = {
  /**
   * Error code.
   */
  error: string;
  /**
   * Error message.
   */
  message?: string;
};

export type SwapErrorReason = "rejected_by_user" | "swap_failed";

export type SwapTokenResult =
  | {
      success: true;
      swap: SwapTokenDetails;
    }
  | {
      success: false;
      reason: SwapErrorReason;
      error?: SwapTokenErrorDetails;
    };
```

## Notes

This action opens the native swap interface in the Farcaster client, allowing users to swap tokens without leaving the Mini App context.
