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

# Submit Swap Event

> Submit a swap lifecycle event for tracking

Submits a swap lifecycle event to Hypermid for analytics and tracking purposes. Use this to report when users interact with your swap UI or when swap steps are completed.

<ParamField body="event" type="string" required>
  The event type. Possible values: `quote_requested`, `quote_received`, `swap_started`, `swap_signed`, `swap_completed`, `swap_failed`, `swap_cancelled`.
</ParamField>

<ParamField body="transactionId" type="string">
  The transaction ID or quote ID associated with this event.
</ParamField>

<ParamField body="fromChain" type="number">
  Source chain ID.
</ParamField>

<ParamField body="toChain" type="number">
  Destination chain ID.
</ParamField>

<ParamField body="fromToken" type="string">
  Source token address.
</ParamField>

<ParamField body="toToken" type="string">
  Destination token address.
</ParamField>

<ParamField body="fromAmount" type="string">
  Amount being swapped.
</ParamField>

<ParamField body="txHash" type="string">
  Transaction hash (for signed/completed/failed events).
</ParamField>

<ParamField body="metadata" type="object">
  Additional metadata to attach to the event.
</ParamField>

<ResponseExample>
  ```json 200 theme={"system"}
  {
    "data": {
      "eventId": "evt_abc123",
      "received": true
    },
    "error": null,
    "meta": {
      "requestId": "c9f0a1b2-c3d4-5678-2345-789012345678",
      "timestamp": 1711234587,
      "rateLimit": {
        "limit": 2000,
        "remaining": 1971,
        "reset": 1711234627
      }
    }
  }
  ```
</ResponseExample>

<CodeGroup>
  ```typescript TypeScript theme={"system"}
  await client.submitSwapEvent({
    event: "swap_completed",
    transactionId: "txn_abc123",
    fromChain: 1,
    toChain: 42161,
    fromToken: "0x0000000000000000000000000000000000000000",
    toToken: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
    fromAmount: "1000000000000000000",
    txHash: "0xCompletedTxHash",
    metadata: {
      userAgent: "MyDeFiApp/1.0",
      sessionId: "sess_xyz",
    },
  });
  ```

  ```bash cURL theme={"system"}
  curl -X POST "https://api.hypermid.io/v1/swap-event" \
    -H "Content-Type: application/json" \
    -H "X-API-Key: your-api-key" \
    -d '{
      "event": "swap_completed",
      "transactionId": "txn_abc123",
      "fromChain": 1,
      "toChain": 42161,
      "txHash": "0xCompletedTxHash"
    }'
  ```

  ```go Go theme={"system"}
  body := `{
    "event": "swap_completed",
    "transactionId": "txn_abc123",
    "fromChain": 1,
    "toChain": 42161,
    "txHash": "0xCompletedTxHash"
  }`

  req, _ := http.NewRequest("POST",
      "https://api.hypermid.io/v1/swap-event",
      strings.NewReader(body))
  req.Header.Set("Content-Type", "application/json")
  req.Header.Set("X-API-Key", "your-api-key")
  resp, _ := http.DefaultClient.Do(req)
  ```
</CodeGroup>

<Tip>
  Submitting swap events improves your analytics in the Partner Dashboard and helps Hypermid optimize route selection for your users.
</Tip>


## OpenAPI

````yaml POST /v1/swap-event
openapi: 3.0.3
info:
  title: Hypermid Partner API
  version: 1.0.0
  description: >-
    Cross-chain swap aggregator API. Supports 30+ EVM chains, Solana, Bitcoin,
    Sui, and Near Intents chains (NEAR, TON, Tron, XRP, etc.).


    ## Authentication

    Pass your API key via the `X-API-Key` header. Public endpoints work without
    a key (anonymous tier). Partner endpoints (`/v1/partner/*`) require a valid
    key.


    ## Rate Limits

    - **Anonymous**: 30 requests/minute (per IP)

    - **Partner (authenticated)**: 100 requests/minute (per API key)


    These limits are designed for human-driven widget usage and mirror our
    upstream aggregator (LiFi) limits to prevent any single user from exhausting
    shared quota.


    Rate limit info is returned in `meta.rateLimit` on every response.


    ## Response Envelope

    All responses follow the shape:

    ```json

    { "data": <T | null>, "error": <{ code, message, details? } | null>, "meta":
    { "requestId", "timestamp", "rateLimit?" } }

    ```
  contact:
    name: Hypermid
    url: https://hypermid.io
servers:
  - url: https://api.hypermid.io
    description: Production
security:
  - ApiKeyAuth: []
  - {}
tags:
  - name: Swap
    description: Cross-chain swap quoting, routing, status, and reference data
  - name: Execute
    description: Transaction execution and deposit management for Near Intents swaps
  - name: On-Ramp
    description: Fiat-to-crypto on-ramp via RampNow
  - name: Partner
    description: Partner account, analytics, and webhook management (requires X-API-Key)
  - name: Tracking
    description: Swap event tracking for partner attribution
  - name: System
    description: Health check and API metadata
paths:
  /v1/swap-event:
    post:
      tags:
        - Tracking
      summary: Record a swap event
      description: >-
        Records or updates a swap event for partner attribution. The partner_id
        is derived from the authenticated API key context (never from the
        request body). If a pending swap matching the wallet/token pair exists,
        it will be updated; otherwise a new record is inserted.
      operationId: postSwapEvent
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SwapEvent'
      responses:
        '200':
          description: Event recorded
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/ApiResponse'
                  - type: object
                    properties:
                      data:
                        type: object
                        properties:
                          updated:
                            type: boolean
                            description: True if an existing pending record was updated
                          id:
                            type: integer
                            description: Record ID
        '400':
          $ref: '#/components/responses/BadRequest'
        '500':
          $ref: '#/components/responses/UpstreamError'
components:
  schemas:
    SwapEvent:
      type: object
      properties:
        provider:
          type: string
        from_chain:
          type: string
        from_token:
          type: string
        to_chain:
          type: string
        to_token:
          type: string
        amount_usd:
          type: number
        fee_usd:
          type: number
        tx_hash:
          type: string
        wallet_hash:
          type: string
        status:
          type: string
          enum:
            - pending
            - completed
            - failed
        from_amount:
          type: string
        to_amount:
          type: string
        duration_seconds:
          type: integer
        error_message:
          type: string
      required:
        - status
    ApiResponse:
      type: object
      properties:
        data:
          description: Response payload (null on error)
        error:
          nullable: true
          type: object
          properties:
            code:
              type: string
              example: INVALID_PARAMS
            message:
              type: string
              example: 'Missing required parameters: fromChain'
            details:
              type: object
              additionalProperties: true
          required:
            - code
            - message
        meta:
          $ref: '#/components/schemas/Meta'
      required:
        - data
        - error
        - meta
    Meta:
      type: object
      properties:
        requestId:
          type: string
          format: uuid
        timestamp:
          type: integer
          description: Unix epoch seconds
        rateLimit:
          type: object
          properties:
            limit:
              type: integer
            remaining:
              type: integer
            reset:
              type: integer
              description: Unix epoch seconds when the window resets
      required:
        - requestId
        - timestamp
  responses:
    BadRequest:
      description: Invalid or missing parameters
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiResponse'
    UpstreamError:
      description: Upstream provider error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiResponse'
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: X-API-Key
      description: >-
        Partner API key. Optional for public endpoints, required for
        /v1/partner/*.

````