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

# Swap

> Build and execute token swap transactions

## Overview

The swap endpoint builds token swap transactions on Solana. You receive a serialized transaction that you sign and broadcast using your wallet.

<Note>
  This endpoint builds the transaction but does not execute it. You must sign and send the transaction yourself.
</Note>

## Supported Platforms

* **Pump.fun** - Launch platform tokens
* **PumpSwap** - Pump.fun liquidity pools
* **Orca** - Concentrated liquidity
* **Meteora** - Dynamic pools
* **Moonshot** - New launches
* **Raydium** - V4 AMM, CPMM, Launchpad
* **Jupiter** - Aggregated routing

## SDK Examples

<CodeGroup>
  ```javascript JavaScript theme={null}
  import { SolanaTracker } from 'solana-swap';

  const tracker = new SolanaTracker('YOUR_API_KEY', 'YOUR_PRIVATE_KEY');

  // Basic swap
  const swap = await tracker.swap({
    from: 'So11111111111111111111111111111111111111112', // SOL
    to: '4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R',
    fromAmount: 0.1,
    slippage: 10,
    payer: 'YOUR_WALLET_ADDRESS',
    priorityFee: 0.000005,
    txVersion: 'v0'
  });

  console.log('Transaction:', swap.txn);
  ```

  ```python Python theme={null}
  from solana_swap import SolanaTracker

  tracker = SolanaTracker('YOUR_API_KEY', 'YOUR_PRIVATE_KEY')

  # Basic swap
  swap = tracker.swap(
      from_token='So11111111111111111111111111111111111111112',
      to_token='4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R',
      from_amount=0.1,
      slippage=10,
      payer='YOUR_WALLET_ADDRESS',
      priority_fee=0.000005,
      tx_version='v0'
  )

  print('Transaction:', swap['txn'])
  ```

  ```bash cURL theme={null}
  curl -X GET "https://swap-v2.solanatracker.io/swap?from=So11111111111111111111111111111111111111112&to=4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R&fromAmount=0.1&slippage=10&payer=YOUR_WALLET_ADDRESS&priorityFee=0.000005&txVersion=v0"
  ```
</CodeGroup>

## Key Parameters

### Amount Formats

The `fromAmount` parameter accepts:

* **Numeric**: `1`, `0.5` - Exact amount
* **Auto**: `"auto"` - Entire wallet balance
* **Percentage**: `"50%"`, `"25%"` - Percentage of balance

### Priority Fees

```javascript theme={null}
// Manual fee
{ priorityFee: 0.000005 }

// Automatic with level
{ 
  priorityFee: "auto",
  priorityFeeLevel: "high" // min, low, medium, high, veryHigh, unsafeMax
}
```

### Custom Fees

Add your own fees for monetization:

```javascript theme={null}
{
  fee: "YOUR_WALLET:0.1", // 0.1% to your wallet
  feeType: "add" // or "deduct" (SOL only)
}
```

## Examples

### Swap with Auto Amount

```javascript theme={null}
// Swap entire balance
const swap = await tracker.swap({
  from: 'So11111111111111111111111111111111111111112',
  to: '4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R',
  fromAmount: "auto",
  slippage: 15,
  payer: 'YOUR_WALLET_ADDRESS'
});
```

### Swap with Percentage

```javascript theme={null}
// Swap 50% of balance
const swap = await tracker.swap({
  from: 'TOKEN_ADDRESS',
  to: 'So11111111111111111111111111111111111111112',
  fromAmount: "50%",
  slippage: 10,
  payer: 'YOUR_WALLET_ADDRESS'
});
```

### Swap with Custom Fee

```javascript theme={null}
// Add 0.1% fee
const swap = await tracker.swap({
  from: 'So11111111111111111111111111111111111111112',
  to: '4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R',
  fromAmount: 1,
  slippage: 10,
  payer: 'YOUR_WALLET_ADDRESS',
  fee: 'YOUR_FEE_WALLET:0.1',
  feeType: 'add'
});
```

## Response Structure

```json theme={null}
{
  "txn": "BASE64_ENCODED_TRANSACTION",
  "rate": {
    "amountIn": 0.1,
    "amountOut": 81.631985,
    "minAmountOut": 73.4687865,
    "currentPrice": 0.012219167460548153,
    "executionPrice": 0.010997250714493338,
    "priceImpact": 0.002517,
    "fee": 0.000005,
    "platformFee": 9000000,
    "platformFeeUI": 0.009
  },
  "timeTaken": 0.016,
  "type": "v0"
}
```

## Platform Fees

Standard fee: **0.5%** of transaction value

* Deducted from output
* Shown in `platformFee` (lamports) and `platformFeeUI` (SOL)
* Volume discounts available

<Tip>
  Contact [swap-api@solanatracker.io](mailto:swap-api@solanatracker.io) for volume pricing
</Tip>

## Common Errors

| Error                  | Solution                          |
| ---------------------- | --------------------------------- |
| Invalid token address  | Verify addresses are valid        |
| Invalid amount         | Use number, "auto", or percentage |
| Invalid slippage       | Set between 0-100                 |
| Token has no pools     | Token may be delisted             |
| Insufficient liquidity | Try smaller amount                |

## Next Steps

<CardGroup cols={2}>
  <Card title="Rate Endpoint" icon="chart-line" href="/swap-api/rate">
    Get quotes before swapping
  </Card>

  <Card title="JavaScript SDK" icon="js" href="https://github.com/YZYLAB/solana-swap">
    Install the SDK
  </Card>
</CardGroup>


## OpenAPI

````yaml swap-api/openapi.json get /swap
openapi: 3.1.0
info:
  title: Solana Tracker - Swap API
  description: >-
    The Solana Tracker Swap API offers seamless, zero-delay access to Solana's
    dynamic token marketplace. Trade tokens the moment they launch with our
    high-performance infrastructure. Supports Pump.fun, PumpSwap, Moonshot,
    Boop, Orca, Meteora, Raydium, and any pool supported by Jupiter.
  version: 2.0.0
  contact:
    name: Solana Tracker Support
    email: swap-api@solanatracker.io
    url: https://discord.com/invite/JH2e9rR9fc
  x-fees:
    standard: 0.5%
    highVolume: 0-0.5%
servers:
  - url: https://swap-v2.solanatracker.io
    description: Production server
security: []
tags:
  - name: Swap
    description: Token swap operations
  - name: Rate
    description: Rate and price quote operations
externalDocs:
  description: Full API Documentation
  url: https://docs.solanatracker.io/swap-api
paths:
  /swap:
    get:
      summary: Build Swap Transaction
      description: >-
        Build a swap transaction on Solana. Sign and send the transaction using
        your own wallet infrastructure.
      operationId: swapGet
      parameters:
        - name: from
          in: query
          required: true
          description: The base token address
          schema:
            type: string
            example: So11111111111111111111111111111111111111112
        - name: to
          in: query
          required: true
          description: The quote token address
          schema:
            type: string
            example: 4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R
        - name: fromAmount
          in: query
          required: true
          description: >-
            The amount of the base token to swap. Accepts numeric value, 'auto'
            for full wallet balance, or percentage like '50%'
          schema:
            oneOf:
              - type: number
                example: 1
              - type: string
                enum:
                  - auto
                example: auto
              - type: string
                pattern: ^[0-9]+(\.[0-9]+)?%$
                example: 50%
        - name: slippage
          in: query
          required: true
          description: >-
            Maximum acceptable slippage percentage or 'auto' for dynamic
            slippage (Beta)
          schema:
            oneOf:
              - type: number
                minimum: 0
                maximum: 100
                example: 10
              - type: string
                enum:
                  - auto
        - name: payer
          in: query
          required: true
          description: Public key of the wallet sending the transaction
          schema:
            type: string
            example: arsc4jbDnzaqcCLByyGo7fg7S2SmcFsWUzQuDtLZh2y
        - name: priorityFee
          in: query
          required: false
          description: Amount in SOL to increase transaction priority or 'auto'
          schema:
            oneOf:
              - type: number
                example: 0.000005
              - type: string
                enum:
                  - auto
        - name: priorityFeeLevel
          in: query
          required: false
          description: Priority level when priorityFee is set to 'auto'
          schema:
            type: string
            enum:
              - min
              - low
              - medium
              - high
              - veryHigh
              - unsafeMax
            default: medium
        - name: txVersion
          in: query
          required: false
          description: Transaction version
          schema:
            type: string
            enum:
              - v0
              - legacy
            default: v0
        - name: fee
          in: query
          required: false
          description: Custom fee for your users in format 'WALLET_ADDRESS:PERCENTAGE'
          schema:
            type: string
            pattern: ^[a-zA-Z0-9]+:[0-9]+(\.[0-9]+)?$
            example: arsc4jbDnzaqcCLByyGo7fg7S2SmcFsWUzQuDtLZh2y:0.1
        - name: customTip
          in: query
          required: false
          description: >-
            Custom tip for Jito or similar services in format
            'WALLET_ADDRESS:SOL_AMOUNT'
          schema:
            type: string
            pattern: ^[a-zA-Z0-9]+:[0-9]+(\.[0-9]+)?$
        - name: feeType
          in: query
          required: false
          description: >-
            Fee application type. 'deduct' option is only used when the from
            address is SOL
          schema:
            type: string
            enum:
              - add
              - deduct
            default: add
        - name: onlyDirectRoutes
          in: query
          required: false
          description: Disable multi-hop swaps
          schema:
            type: boolean
            default: false
      responses:
        '200':
          description: Successful swap transaction
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SwapResponse'
        '400':
          description: Bad request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    SwapResponse:
      type: object
      properties:
        txn:
          type: string
          description: Base64 encoded transaction
          example: BASE64_TX
        rate:
          type: object
          properties:
            amountIn:
              type: number
              description: Amount of input token
              example: 1
            amountOut:
              type: number
              description: Amount of output token
              example: 81.631985
            minAmountOut:
              type: number
              description: Minimum amount out after slippage
              example: 73.4687865
            currentPrice:
              type: number
              description: Current market price
              example: 0.012219167460548153
            executionPrice:
              type: number
              description: Actual execution price
              example: 0.010997250714493338
            priceImpact:
              type: number
              description: Price impact as a decimal
              example: 0.002517
            fee:
              type: number
              description: Transaction fee
              example: 0.000005
            baseCurrency:
              type: object
              properties:
                mint:
                  type: string
                  description: Base token mint address
                decimals:
                  type: integer
                  description: Base token decimals
            quoteCurrency:
              type: object
              properties:
                mint:
                  type: string
                  description: Quote token mint address
                decimals:
                  type: integer
                  description: Quote token decimals
            platformFee:
              type: integer
              description: Platform fee in lamports
              example: 9000000
            platformFeeUI:
              type: number
              description: Platform fee in SOL
              example: 0.009
        timeTaken:
          type: number
          description: Time taken for the operation in seconds
          example: 0.016
        type:
          type: string
          enum:
            - v0
            - legacy
          description: Transaction type
          example: legacy
    Error:
      type: object
      required:
        - error
      properties:
        error:
          type: string
          description: Error message
          examples:
            - An internal error occurred
            - Invalid or missing 'from' or 'to' token address
            - Invalid amount
            - Invalid slippage tolerance (should be between 0 and 100%)
        details:
          type: string
          description: Additional error details
          examples:
            - Unable to fetch pools for token
            - Token has no pools
            - No pools with liquidity found

````