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

# 构建 swap 交易（固定输入）

> 为固定输入数量生成序列化的 swap 交易。
需要先从 `/compute/swap-base-in` 获取成功的计算结果。




## OpenAPI

````yaml /zh/api-reference/openapi/route-api-v2.yaml post /transaction/swap-base-in
openapi: 3.0.3
info:
  title: Raydium Transaction API（Route V2）
  version: 1.0.0
  description: >
    服务端 swap 交易构建器，适用于 Solana。此 API 生成序列化的 swap 交易，无需客户端运行 RPC 连接或完整的 Raydium
    SDK。


    响应遵循标准信封格式：

    - **成功**：`{ id: string, success: true, data: {...} }`

    - **错误**：`{ id: string, success: false, msg: string }`
  contact:
    name: Raydium
    url: https://raydium.io
servers:
  - url: https://transaction-v1.raydium.io
    description: Mainnet
  - url: https://transaction-v1-devnet.raydium.io
    description: Devnet
security: []
tags:
  - name: Compute
    description: 用于 swap 报价计算的只读端点（不构建交易）。
  - name: Transaction
    description: 构建序列化的 swap 交易，可直接签名并广播。
paths:
  /transaction/swap-base-in:
    post:
      tags:
        - Transaction
      summary: 构建 swap 交易（固定输入）
      description: |
        为固定输入数量生成序列化的 swap 交易。
        需要先从 `/compute/swap-base-in` 获取成功的计算结果。
      operationId: buildSwapTransactionBaseIn
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/BuildTransactionRequest'
      responses:
        '200':
          description: 序列化交易构建成功。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TransactionResponse'
        '400':
          description: 请求体无效或计算状态异常。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
components:
  schemas:
    BuildTransactionRequest:
      type: object
      required:
        - wallet
        - swapResponse
        - txVersion
        - computeUnitPriceMicroLamports
      properties:
        wallet:
          type: string
          description: 签名者钱包地址（base58）。
          example: '11111111111111111111111111111111'
        swapResponse:
          type: object
          description: 来自 compute 端点的完整响应对象。
          properties:
            id:
              type: string
            success:
              type: boolean
            version:
              type: string
            data:
              type: object
        txVersion:
          type: string
          enum:
            - V0
            - LEGACY
          description: Solana 交易版本。
          example: V0
        computeUnitPriceMicroLamports:
          type: string
          description: 计算单元价格，单位为 micro-lamports（用于优先费用）。
          example: '1000'
        wrapSol:
          type: boolean
          description: 若输入为原生 SOL，是否自动 wrap SOL。
          example: false
        unwrapSol:
          type: boolean
          description: 是否将输出中的 WSOL 解包为 SOL。
          example: false
        inputAccount:
          type: string
          description: 输入代币账户地址（可选）。若不 wrap SOL 则必填。
          example: TokenAccount1111111111111111111111111111111111
        outputAccount:
          type: string
          description: 输出代币账户地址（可选）。
          example: TokenAccount2222222222222222222222222222222222
        jitoInfo:
          type: object
          description: 用于 MEV 保护的 Jito bundle 参数（可选）。
          properties:
            address:
              type: string
              description: Jito bundle 提交地址。
            amount:
              type: string
              description: Bundle 小费金额，单位为 lamports。
        referrerWallet:
          type: string
          description: 用于手续费归集的推荐人钱包地址（可选）。
          example: ReferrerWallet1111111111111111111111111111111111
    TransactionResponse:
      type: object
      properties:
        id:
          type: string
          description: 唯一请求标识符。
          example: 550e8400-e29b-41d4-a716-446655440000
        success:
          type: boolean
          description: 交易构建是否成功。
          example: true
        version:
          type: string
          example: V1
        data:
          type: object
          description: 交易数据。
          properties:
            transaction:
              type: string
              description: Base64 编码的版本化交易（可直接签名）。
            addressLookupTableAddresses:
              type: array
              description: 地址查找表地址（当 txVersion=V0 时）。
              items:
                type: string
    ErrorResponse:
      type: object
      properties:
        id:
          type: string
          description: 请求的唯一标识符。
        success:
          type: boolean
          example: false
        version:
          type: string
          example: V1
        msg:
          type: string
          description: 错误信息码（例如 REQ_SLIPPAGE_BPS_ERROR、REQ_WALLET_ERROR）。

````