> ## 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.

# 構建交換交易（固定輸出）

> 為所需輸出金額生成序列化的交換交易。
需要從 `/compute/swap-base-out` 獲得成功的計算回應。




## OpenAPI

````yaml /zh-Hant/api-reference/openapi/route-api-v2.yaml post /transaction/swap-base-out
openapi: 3.0.3
info:
  title: Raydium 交易 API（Route V2）
  version: 1.0.0
  description: |
    Solana 伺服器端交換交易建構工具。此 API 生成序列化的交換交易，無需客戶端運行 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: 用於交換報價計算的唯讀端點（無交易建構）。
  - name: Transaction
    description: 構建已序列化的交換交易，準備簽署和廣播。
paths:
  /transaction/swap-base-out:
    post:
      tags:
        - Transaction
      summary: 構建交換交易（固定輸出）
      description: |
        為所需輸出金額生成序列化的交換交易。
        需要從 `/compute/swap-base-out` 獲得成功的計算回應。
      operationId: buildSwapTransactionBaseOut
      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: 來自計算端點的完整回應物件。
          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: 微 lamports 計算單位價格（用於優先費用）。
          example: '1000'
        wrapSol:
          type: boolean
          description: 如果輸入為原生 SOL，是否包裝 SOL。
          example: false
        unwrapSol:
          type: boolean
          description: 輸出是否解除包裝 WSOL 為 SOL。
          example: false
        inputAccount:
          type: string
          description: 輸入的選用代幣帳戶位址。如果不包裝 SOL 則為必填。
          example: TokenAccount1111111111111111111111111111111111
        outputAccount:
          type: string
          description: 輸出的選用代幣帳戶位址。
          example: TokenAccount2222222222222222222222222222222222
        jitoInfo:
          type: object
          description: Jito bundle 的選用參數（用於 MEV 保護）。
          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）。

````