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

# Generate Swap Transaction

> Generate complete transaction data for executing a token swap via the AKKA router. The endpoint performs a full exact quote (graph walk), validates the user's token balance and allowance, and returns a ready-to-sign transaction object.

<Info>
  This endpoint always performs an **exact quote** (full graph walk) regardless of the chain's default quote policy. The returned `dstAmount` is the precise expected output.
</Info>

## Using the response

The response includes a `tx` object that is ready to sign and broadcast:

```javascript theme={null}
const { tx } = swapResponse;

const hash = await walletClient.sendTransaction({
  to: tx.to,
  data: tx.data,
  value: BigInt(tx.value),
  gasPrice: BigInt(tx.gasPrice),
  gas: BigInt(tx.gas),
});
```

## Slippage recommendations

| Swap type            | Recommended slippage |
| -------------------- | -------------------- |
| Stable-to-stable     | 0.1 — 0.5%           |
| Major tokens         | 0.5 — 1%             |
| Low-liquidity tokens | 1 — 5%               |

## Balance and allowance validation

When `from` is provided, the API validates:

* **Balance**: The wallet has enough tokens to cover the swap amount
* **Allowance**: The AKKA Router is approved to spend enough tokens

If either check fails, the API returns a `400` error with a descriptive message.


## OpenAPI

````yaml GET /swap/v1/{chainId}/swap
openapi: 3.0.3
info:
  title: AKKA Finance API
  version: 1.0.0
  description: >-
    AKKA Finance liquidity aggregation API. Find the best swap routes across
    multiple DEXes and execute token swaps with optimal pricing.
  contact:
    name: AKKA Finance
    url: https://akka.finance
    email: support@akka.finance
servers:
  - url: https://api.akka.finance
    description: Production
security:
  - apiKey: []
paths:
  /swap/v1/{chainId}/swap:
    get:
      tags:
        - Quote & Swap
      summary: Generate swap transaction data
      description: >-
        Generate complete transaction data for executing a token swap via the
        AKKA router. The endpoint performs a full exact quote (graph walk),
        validates the user's token balance and allowance, and returns a
        ready-to-sign transaction object.
      operationId: getSwap
      parameters:
        - name: chainId
          in: path
          required: true
          description: Blockchain chain ID
          schema:
            type: integer
            enum:
              - 999
            example: 999
        - name: src
          in: query
          required: true
          description: >-
            Source token contract address. Use
            `0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee` for the native token.
          schema:
            type: string
            pattern: ^0x[a-fA-F0-9]{40}$
            example: '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'
        - name: dst
          in: query
          required: true
          description: Destination token contract address.
          schema:
            type: string
            pattern: ^0x[a-fA-F0-9]{40}$
            example: '0xB8CE59FC3717ada4C02eaDF9682A9e934F625ebb'
        - name: amount
          in: query
          required: true
          description: Amount to swap in the smallest unit (wei).
          schema:
            type: string
            example: '1000000000000000000'
        - name: from
          in: query
          required: false
          description: >-
            Wallet address executing the swap. When provided, the API validates
            that the wallet has sufficient token balance and allowance.
          schema:
            type: string
            pattern: ^0x[a-fA-F0-9]{40}$
            example: '0xD3C0F471488523b378F2D9C21939c97300c510F5'
        - name: slippage
          in: query
          required: true
          description: >-
            Maximum acceptable slippage as a percentage. Range: 0 to 50.
            Recommended: 0.5 to 3 for most swaps.
          schema:
            type: number
            minimum: 0
            maximum: 50
            example: 1
        - name: gasPrice
          in: query
          required: false
          description: >-
            Custom gas price in wei. If omitted, the current network gas price
            is used.
          schema:
            type: string
            example: '1000000000'
        - name: gasLimit
          in: query
          required: false
          description: >-
            Custom gas limit. If omitted, the API estimates gas with a 20%
            safety buffer.
          schema:
            type: integer
            example: 500000
        - name: includeTokensInfo
          in: query
          required: false
          description: Include `srcToken` and `dstToken` metadata in the response.
          schema:
            type: boolean
            default: false
        - name: includeGas
          in: query
          required: false
          description: Include estimated gas amount in the response.
          schema:
            type: boolean
            default: false
      responses:
        '200':
          description: Swap transaction data generated successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SwapResponse'
              example:
                dstAmount: '12723902882990271'
                tx:
                  from: '0xD3C0F471488523b378F2D9C21939c97300c510F5'
                  to: '0xcce7452db4392b40aa0e1592a7c486e13bf69654'
                  data: 0x...
                  value: '1000000000000000000'
                  gasPrice: '1000000000'
                  gas: '231973'
                encodedTx: 0x...
        '400':
          description: >-
            Bad request — invalid parameters, no route found, insufficient
            balance, or insufficient allowance
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                noRoute:
                  summary: No route found
                  value:
                    statusCode: 400
                    message: No route found for the given token pair
                    error: Bad Request
                    timestamp: '2025-01-15T12:00:00.000Z'
                    path: /swap/v1/999/swap
                insufficientBalance:
                  summary: Insufficient balance
                  value:
                    statusCode: 400
                    message: 'Not enough balance. Current balance: 500000000000000000'
                    error: Bad Request
                    timestamp: '2025-01-15T12:00:00.000Z'
                    path: /swap/v1/999/swap
                insufficientAllowance:
                  summary: Insufficient allowance
                  value:
                    statusCode: 400
                    message: 'Not enough allowance. Current allowance: 0'
                    error: Bad Request
                    timestamp: '2025-01-15T12:00:00.000Z'
                    path: /swap/v1/999/swap
        '404':
          description: Chain or token not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
components:
  schemas:
    SwapResponse:
      type: object
      required:
        - dstAmount
        - tx
        - encodedTx
      properties:
        dstAmount:
          type: string
          description: Expected output amount in the smallest unit (wei)
          example: '12723902882990271'
        srcToken:
          $ref: '#/components/schemas/TokenInfo'
          description: Source token information (when `includeTokensInfo=true`)
        dstToken:
          $ref: '#/components/schemas/TokenInfo'
          description: Destination token information (when `includeTokensInfo=true`)
        gas:
          type: string
          description: Estimated gas amount (when `includeGas=true`)
          example: '231973'
        tx:
          $ref: '#/components/schemas/TransactionData'
        encodedTx:
          type: string
          description: >-
            ABI-encoded transaction tuple (from, to, data, value, gasPrice, gas)
            as a hex string. Allows decoding and executing the swap without
            needing the contract ABI.
          example: 0x...
    ErrorResponse:
      type: object
      required:
        - statusCode
        - message
        - error
        - timestamp
        - path
      properties:
        statusCode:
          type: integer
          description: HTTP status code
          example: 400
        message:
          type: string
          description: Human-readable error description
          example: No route found for the given token pair
        error:
          type: string
          description: Error type
          example: Bad Request
        timestamp:
          type: string
          format: date-time
          description: When the error occurred
          example: '2025-01-15T12:00:00.000Z'
        path:
          type: string
          description: API endpoint path that produced the error
          example: /swap/v1/999/quote
    TokenInfo:
      type: object
      required:
        - address
        - symbol
        - name
        - decimals
      description: Token metadata included when `includeTokensInfo=true`
      properties:
        address:
          type: string
          description: Token contract address
          example: '0x5555555555555555555555555555555555555555'
        symbol:
          type: string
          description: Token ticker symbol
          example: WHYPE
        name:
          type: string
          description: Full token name
          example: Wrapped HYPE
        decimals:
          type: integer
          description: Number of decimal places
          example: 18
        logoUri:
          type: string
          nullable: true
          description: URL to the token logo image
          example: null
    TransactionData:
      type: object
      required:
        - to
        - data
        - value
        - gasPrice
        - gas
      description: Ready-to-sign transaction object. Send this directly to the blockchain.
      properties:
        from:
          type: string
          description: Sender wallet address
          example: '0xD3C0F471488523b378F2D9C21939c97300c510F5'
        to:
          type: string
          description: AKKA Router contract address
          example: '0xcce7452db4392b40aa0e1592a7c486e13bf69654'
        data:
          type: string
          description: Encoded transaction calldata
          example: 0x...
        value:
          type: string
          description: >-
            Native token value to send (in wei). Non-zero only for
            native-to-token swaps.
          example: '1000000000000000000'
        gasPrice:
          type: string
          description: Gas price in wei
          example: '1000000000'
        gas:
          type: string
          description: Gas limit (includes 20% safety buffer)
          example: '231973'
  securitySchemes:
    apiKey:
      type: apiKey
      in: header
      name: apikey
      description: API key for authentication. Contact AKKA on Telegram to obtain your key.

````