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

# Swap wallet balances

> Convert between USD and USDC or USDT within your account.

Supported pairs are USD to/from USDC and USD to/from USDT. Conversion is 1:1 with 3% deducted from proceeds. This converts wallet balances; it does not send funds on a blockchain. Direct USDC-to-USDT swaps are not supported.

```json theme={null}
{
  "amount": "100",
  "from_currency": "USD",
  "to_currency": "USDC",
  "reference": "swap-100",
  "callback_url": "https://merchant.example/payments",
  "quote": true
}
```

Quote response:

```json theme={null}
{
  "status": "success",
  "quote": {
    "source_currency": "USD",
    "destination_currency": "USDC",
    "amount": "100",
    "exchange_rate": "1",
    "amount_received": "97",
    "total_fees": "3",
    "total_debit": "100",
    "pricing": "temporary_fixed"
  }
}
```

Execute with `"quote": false`. A successful swap returns HTTP `200` with a completed transaction and its quote. Both wallets must be active and the source wallet must have sufficient balance.


## OpenAPI

````yaml api-reference/openapi.json POST /swap
openapi: 3.0.3
info:
  title: Sarafa Business API
  version: 3.0.0
  description: >-
    Server-side access to your verified organization's account. Use Bearer API
    keys, decimal-string amounts, and unique merchant references. Charge,
    transfer, and swap default to quotes. Only transaction.status = completed
    confirms payment.
servers:
  - url: https://api.sarafa.site/v3
    description: Production
security:
  - bearerAuth: []
tags:
  - name: Accounts
  - name: Transactions
  - name: Payments
  - name: Checkout
paths:
  /swap:
    post:
      tags:
        - Payments
      summary: Swap wallet balances
      description: >-
        Convert USD to/from USDC or USDT at 1:1, with 3% deducted from proceeds.
        This moves wallet balances, not blockchain funds. Quote defaults to
        true.
      operationId: swap
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SwapRequest'
            examples:
              usdToUsdc:
                summary: Quote a USD to USDC swap
                value:
                  amount: '100'
                  from_currency: USD
                  to_currency: USDC
                  reference: swap-100
                  callback_url: https://merchant.example/payments
                  quote: true
      responses:
        '200':
          description: >-
            Quote, or resolved execution. Only transaction.status = completed
            confirms payment.
          headers:
            X-Request-Id:
              $ref: '#/components/headers/RequestId'
          content:
            application/json:
              schema:
                oneOf:
                  - $ref: '#/components/schemas/QuoteResponse'
                  - $ref: '#/components/schemas/PaymentResponse'
              example:
                status: success
                quote:
                  source_currency: USD
                  destination_currency: USDC
                  amount: '100'
                  exchange_rate: '1'
                  amount_received: '97'
                  total_fees: '3'
                  total_debit: '100'
                  pricing: temporary_fixed
        '400':
          $ref: '#/components/responses/Error400'
        '401':
          $ref: '#/components/responses/Error401'
        '403':
          $ref: '#/components/responses/Error403'
        '404':
          $ref: '#/components/responses/Error404'
        '409':
          $ref: '#/components/responses/Error409'
        '500':
          $ref: '#/components/responses/Error500'
        '503':
          $ref: '#/components/responses/Error503'
components:
  schemas:
    SwapRequest:
      type: object
      required:
        - amount
        - reference
        - callback_url
        - from_currency
        - to_currency
      properties:
        amount:
          type: string
          pattern: ^[0-9]+([.][0-9]{1,18})?$
          description: >-
            Positive decimal string, not a JSON number. Zero is invalid.
            Currency-specific precision and payment limits also apply.
          example: '100.00'
        reference:
          type: string
          minLength: 1
          maxLength: 128
          description: >-
            Your idempotency reference, unique across charge, transfer, swap,
            and checkout creation within your organization. Reuse it with
            unchanged details for execution retries.
        callback_url:
          type: string
          format: uri
          pattern: ^https://
          description: >-
            HTTPS URL without embedded credentials. Required even for quotes.
            Receives signed payment callbacks.
          example: https://merchant.example/payments
        quote:
          type: boolean
          default: true
          description: >-
            True returns a quote without moving funds or creating a transaction.
            Set false to execute.
        from_currency:
          type: string
          enum:
            - USD
            - USDC
            - USDT
        to_currency:
          type: string
          enum:
            - USD
            - USDC
            - USDT
      additionalProperties: false
      description: >-
        Only USD to/from USDC or USDT. The currencies must differ. Conversion is
        1:1, with 3% deducted from proceeds.
      oneOf:
        - properties:
            from_currency:
              enum:
                - USD
            to_currency:
              enum:
                - USDC
                - USDT
        - properties:
            from_currency:
              enum:
                - USDC
                - USDT
            to_currency:
              enum:
                - USD
    QuoteResponse:
      type: object
      required:
        - status
        - quote
      properties:
        status:
          type: string
          enum:
            - success
        quote:
          $ref: '#/components/schemas/Quote'
    PaymentResponse:
      type: object
      required:
        - status
        - transaction
        - quote
      properties:
        status:
          type: string
          enum:
            - success
        transaction:
          $ref: '#/components/schemas/PaymentTransaction'
        quote:
          $ref: '#/components/schemas/NullableQuote'
    Quote:
      type: object
      required:
        - source_currency
        - destination_currency
        - amount
        - exchange_rate
        - amount_received
        - total_fees
        - total_debit
        - pricing
      properties:
        source_currency:
          type: string
        destination_currency:
          type: string
        amount:
          type: string
          description: Decimal string.
        exchange_rate:
          type: string
          description: Decimal string.
        amount_received:
          type: string
          description: Decimal string.
        total_fees:
          type: string
          description: Decimal string.
        total_debit:
          type: string
          description: Decimal string.
        pricing:
          type: string
          enum:
            - temporary_fixed
            - payswitch_estimate
            - payswitch_accepted
        quote_token:
          type: string
          description: >-
            Optional token returned for mobile estimates. Include it on
            execution to detect a changed estimate, and preserve it on execution
            retries.
    PaymentTransaction:
      allOf:
        - $ref: '#/components/schemas/Transaction'
        - type: object
          required:
            - exchange_details
          properties:
            exchange_details:
              type: object
              required:
                - from_currency
                - to_currency
                - rate
                - total
              properties:
                from_currency:
                  type: string
                to_currency:
                  type: string
                rate:
                  type: string
                  description: Decimal string.
                total:
                  type: string
                  description: Decimal string.
              nullable: true
            expires_at:
              type: string
              format: date-time
              description: >-
                Present on approval requests; approval expires 15 minutes after
                creation.
            reason:
              type: string
              nullable: true
              description: >-
                Present on approval requests; rejected or expired when
                applicable.
    NullableQuote:
      type: object
      required:
        - source_currency
        - destination_currency
        - amount
        - exchange_rate
        - amount_received
        - total_fees
        - total_debit
        - pricing
      properties:
        source_currency:
          type: string
        destination_currency:
          type: string
        amount:
          type: string
          description: Decimal string.
        exchange_rate:
          type: string
          description: Decimal string.
        amount_received:
          type: string
          description: Decimal string.
        total_fees:
          type: string
          description: Decimal string.
        total_debit:
          type: string
          description: Decimal string.
        pricing:
          type: string
          enum:
            - temporary_fixed
            - payswitch_estimate
            - payswitch_accepted
        quote_token:
          type: string
          description: >-
            Optional token returned for mobile estimates. Include it on
            execution to detect a changed estimate, and preserve it on execution
            retries.
      nullable: true
    Error:
      type: object
      required:
        - status
        - error
      properties:
        status:
          type: string
          enum:
            - failed
        error:
          type: string
        request_id:
          type: string
          description: >-
            Present on processing errors. Every response also includes
            X-Request-Id.
        issues:
          type: array
          items:
            type: object
            required:
              - path
              - message
            properties:
              path:
                type: array
                items:
                  oneOf:
                    - type: string
                    - type: integer
              message:
                type: string
    Transaction:
      allOf:
        - $ref: '#/components/schemas/TransactionSummary'
        - type: object
          required:
            - currency
            - reference
          properties:
            currency:
              type: string
            reference:
              type: string
              nullable: true
              description: Merchant reference, or null for records without API identity.
    TransactionSummary:
      type: object
      required:
        - tx_reference
        - transaction_type
        - product
        - description
        - amount
        - total_amount
        - total_fees
        - channel
        - status
        - created_at
        - updated_at
      properties:
        tx_reference:
          type: string
          description: >-
            Sarafa payment reference. Newly generated references are 13
            characters; existing longer references remain valid.
          example: TX7A2B9C4D1E0
        transaction_type:
          type: string
          enum:
            - credit
            - debit
        product:
          type: string
        description:
          type: string
        amount:
          type: string
          description: Decimal string.
        total_amount:
          type: string
          description: Decimal string.
        total_fees:
          type: string
          description: Decimal string.
        channel:
          type: string
        status:
          type: string
          description: >-
            Payment state. Only completed confirms payment; pending and
            needs_review are not final. Failed approvals can include a rejection
            or expiry reason.
          example: pending
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
  headers:
    RequestId:
      description: Include this request identifier when contacting support.
      schema:
        type: string
  responses:
    Error400:
      description: >-
        Invalid JSON, fields, amount, precision, or currency/channel
        combination.
      headers:
        X-Request-Id:
          $ref: '#/components/headers/RequestId'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Error401:
      description: Missing, invalid, inactive, or revoked API key.
      headers:
        X-Request-Id:
          $ref: '#/components/headers/RequestId'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Error403:
      description: Required verification or authorization missing.
      headers:
        X-Request-Id:
          $ref: '#/components/headers/RequestId'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Error404:
      description: Resource not found within your organization.
      headers:
        X-Request-Id:
          $ref: '#/components/headers/RequestId'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Error409:
      description: >-
        Conflicting reference, insufficient balance, changed quote, or
        payment-state conflict.
      headers:
        X-Request-Id:
          $ref: '#/components/headers/RequestId'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Error500:
      description: >-
        Processing failure. Retry uncertain executions with the same reference
        and unchanged payload.
      headers:
        X-Request-Id:
          $ref: '#/components/headers/RequestId'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Error503:
      description: >-
        Service failure. Retry uncertain executions with the same reference and
        unchanged payload.
      headers:
        X-Request-Id:
          $ref: '#/components/headers/RequestId'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: sfb_live_<public_identifier>.<secret>
      description: >-
        Use the full key from the merchant dashboard API section. Keep it on
        your server.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.