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

# Get an EVM swap quote

> Get a gasless EVM token swap quote. Requires the relayer to be configured with a `swapChain` (see `FacilitatorOptions`). Returns a quote ID, expected amounts, and EIP-712 typed data for the swap authorization.

**This endpoint is available only when the EVM swap rail is configured.** If `swapChain` is absent, `BuckspayClient.swap()` fails with `SWAP_FAILED`.



## OpenAPI

````yaml /api-reference/openapi.json post /swap/quote
openapi: 3.1.0
info:
  title: Buckspay Facilitator & BFF API
  version: 0.2.0
  description: >-
    HTTP wire contract for the Buckspay SDK. The SDK calls these endpoints
    internally via `@buckspay/relayer`; this reference is for teams building
    their own BFF relay route or calling the facilitator from server-side code.


    All facilitator endpoints require the `x-api-key` header. **The API key is a
    server-side secret - it must only appear in BFF or server-side code and must
    never be shipped to a browser bundle.** Use `createRelayRoute` and
    `createSignerProxyRoute` from `@buckspay/nextjs` to build compliant BFF
    handlers.
servers:
  - url: '{facilitatorUrl}'
    description: >-
      Buckspay facilitator (all endpoints). Set via BUCKSPAY_FACILITATOR_URL on
      the server.
    variables:
      facilitatorUrl:
        default: https://facilitator.buckspay.xyz
        description: Base URL of the Buckspay facilitator service.
security:
  - FacilitatorApiKey: []
tags:
  - name: Relay
    description: >-
      Submit a signed Soroban authorization entry for gasless relaying to the
      Stellar network.
  - name: Fee
    description: >-
      Quote the fee-token amount required for gas-in-token (token gas mode)
      before building the forward() invocation.
  - name: Account State
    description: Read on-chain state for classic G-addresses and contract C-addresses.
  - name: Onboarding
    description: >-
      Build and submit the sponsored onboarding transaction; deploy passkey
      smart-accounts and policy session-accounts.
  - name: Auth
    description: >-
      Signer-proxy for social and email authentication. The BFF forwards these
      requests to the facilitator; provider secrets remain server-side.
  - name: Swap
    description: >-
      Quote a gasless EVM token swap. Requires `swapChain` to be configured in
      the relayer.
paths:
  /swap/quote:
    post:
      tags:
        - Swap
      summary: Get an EVM swap quote
      description: >-
        Get a gasless EVM token swap quote. Requires the relayer to be
        configured with a `swapChain` (see `FacilitatorOptions`). Returns a
        quote ID, expected amounts, and EIP-712 typed data for the swap
        authorization.


        **This endpoint is available only when the EVM swap rail is
        configured.** If `swapChain` is absent, `BuckspayClient.swap()` fails
        with `SWAP_FAILED`.
      operationId: postSwapQuote
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SwapQuoteRequest'
      responses:
        '200':
          description: Swap quote computed.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SwapQuoteResponse'
        '400':
          description: Swap quote failed (pair not supported, slippage too high, etc.).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                error: SWAP_FAILED
                message: pair not supported on this chain
        '401':
          description: Invalid or missing API key.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
components:
  schemas:
    SwapQuoteRequest:
      type: object
      required:
        - chain
        - payer
        - merchant
        - sellToken
        - buyToken
        - sellAmount
      properties:
        chain:
          type: string
          enum:
            - avalanche
            - celo
            - polygon
            - base
            - avalanche-fuji
            - polygon-amoy
            - base-sepolia
            - celo-sepolia
          description: >-
            EVM chain for the swap. Must match the `swapChain` configured in
            `buckspayFacilitator`.
        payer:
          type: string
          description: EVM address of the payer (0x-prefixed).
        merchant:
          type: string
          description: >-
            EVM address where the buy-token is settled. For self-custody swaps
            this equals `payer`.
        sellToken:
          type: string
          description: EVM contract address of the sell token.
        buyToken:
          type: string
          description: EVM contract address of the buy token.
        sellAmount:
          allOf:
            - $ref: '#/components/schemas/Stroops'
          description: >-
            Amount to sell in the sell token's minimal units, as a decimal
            string.
      description: >-
        Request body for `POST /swap/quote`. Corresponds to the body built in
        `buckspayFacilitator.quoteSwap()`.
    SwapQuoteResponse:
      type: object
      required:
        - quoteId
        - sellAmount
        - expectedBuyAmount
        - minBuyAmount
        - typedData
        - needsAuthorization
        - source
        - expiresAt
      properties:
        quoteId:
          type: string
          format: uuid
          description: Unique identifier for this quote.
        sellAmount:
          allOf:
            - $ref: '#/components/schemas/Stroops'
          description: Actual sell amount (may differ from requested amount after routing).
        expectedBuyAmount:
          allOf:
            - $ref: '#/components/schemas/Stroops'
          description: Expected amount of buy token received.
        minBuyAmount:
          allOf:
            - $ref: '#/components/schemas/Stroops'
          description: >-
            Minimum buy amount after slippage. The client enforces this floor
            before submitting.
        typedData:
          type: string
          description: >-
            EIP-712 typed data string for the swap authorization. Required if
            `needsAuthorization` is `true`.
        needsAuthorization:
          type: boolean
          description: >-
            Whether the payer must sign the EIP-712 `typedData` before
            submitting the swap.
        source:
          type: string
          description: Liquidity source or aggregator used to build the quote.
        expiresAt:
          type: string
          description: ISO 8601 timestamp after which the quote is invalid.
      description: >-
        Swap quote returned by `POST /swap/quote`. Mirrors the
        `swapQuoteResponseSchema` zod schema in `@buckspay/relayer`.
    ErrorResponse:
      type: object
      required:
        - error
      properties:
        error:
          type: string
          description: >-
            Machine-readable error code. SDK error codes (e.g.
            `RELAYER_REJECTED`, `SESSION_POLICY_VIOLATION`) or raw facilitator
            codes (e.g. `auth_expired`, `simulation_failed`) depending on
            context.
        message:
          type: string
          description: >-
            Optional human-readable detail. Never log raw upstream messages -
            they may contain addresses or sensitive information.
        details:
          type: object
          description: >-
            Optional structured validation errors (present on BFF-level schema
            failures).
      description: >-
        Error body returned on non-2xx responses. The `error` field maps to a
        `BuckspayErrorCode` or a raw facilitator error string (see
        `mapFacilitatorError` in `@buckspay/relayer`).
    Stroops:
      type: string
      pattern: ^\d+$
      description: >-
        A non-negative integer encoded as a decimal string to preserve
        precision. For Stellar token amounts this is the smallest unit with the
        asset's implied decimals (USDC = 7, i.e. stroops); the same string
        encoding also carries fees, nonces, and EVM swap amounts (which use
        their own token's decimals).
  securitySchemes:
    FacilitatorApiKey:
      type: apiKey
      in: header
      name: x-api-key
      description: >-
        Server-held API key. Injected by the BFF (`createRelayRoute` /
        `createSignerProxyRoute` from `@buckspay/nextjs`). This key must only
        appear in server-side code and must never be shipped to a browser
        bundle.

````