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

# Build Buy Transaction

> Build an unsigned buy transaction to swap SOL or USD1 for tokens via one of the supported DEXs.

The response contains a base64-encoded unsigned `VersionedTransaction`. Sign it locally with your keypair and submit it to the network.


<Warning>
  If you plan to track this buy with the Exit Intelligence Stream, you **must** connect the stream **before** submitting the buy transaction. The stream detects new positions by observing on-chain token arrivals in real time. If the stream is not connected when the buy lands, the position will not be tracked and no exit signals will be generated for it.
</Warning>

<Note>
  Exactly one of `amount` or `amount_in_total` must be provided. `amount` is automatically converted to atomic units based on the `input` asset (SOL: 10^9, USD1: 10^6).
</Note>

## SDK Examples

<CodeGroup>
  ```typescript TypeScript theme={null}
  import { ExitApiClient, type BuildBuyTxRequest } from "@lasersell/lasersell-sdk";

  const client = ExitApiClient.withApiKey("YOUR_API_KEY");

  const request: BuildBuyTxRequest = {
    mint: "TOKEN_MINT_ADDRESS",
    user_pubkey: "YOUR_WALLET_PUBKEY",
    amount: 0.1, // 0.1 SOL
    slippage_bps: 2_000,
  };

  const response = await client.buildBuyTx(request);
  console.log("Unsigned tx (base64):", response.tx);
  ```

  ```python Python theme={null}
  from lasersell_sdk.exit_api import ExitApiClient, BuildBuyTxRequest

  client = ExitApiClient.with_api_key("YOUR_API_KEY")

  request = BuildBuyTxRequest(
      mint="TOKEN_MINT_ADDRESS",
      user_pubkey="YOUR_WALLET_PUBKEY",
      amount=0.1,  # 0.1 SOL
      slippage_bps=2_000,
  )

  response = await client.build_buy_tx(request)
  print("Unsigned tx (base64):", response.tx)
  ```

  ```rust Rust theme={null}
  use lasersell_sdk::exit_api::{ExitApiClient, BuildBuyTxRequest};

  let client = ExitApiClient::with_api_key("YOUR_API_KEY");

  let request = BuildBuyTxRequest {
      mint: "TOKEN_MINT_ADDRESS".into(),
      user_pubkey: "YOUR_WALLET_PUBKEY".into(),
      amount: Some(0.1), // 0.1 SOL
      slippage_bps: 2_000,
      ..Default::default()
  };

  let response = client.build_buy_tx(&request).await?;
  println!("Unsigned tx (base64): {}", response.tx);
  ```

  ```go Go theme={null}
  import lasersell "github.com/lasersell/lasersell-sdk/go"

  client := lasersell.NewExitAPIClientWithAPIKey("YOUR_API_KEY")

  amount := 0.1 // 0.1 SOL
  resp, err := client.BuildBuyTx(ctx, lasersell.BuildBuyTxRequest{
      Mint:        "TOKEN_MINT_ADDRESS",
      UserPubkey:  "YOUR_WALLET_PUBKEY",
      Amount:      &amount,
      SlippageBps: 2_000,
  })
  if err != nil {
      log.Fatal(err)
  }
  fmt.Println("Unsigned tx (base64):", resp.Tx)
  ```
</CodeGroup>

## Error Responses

See [Error Handling](/api/exit-api/error-handling) for the full error envelope specification and retryable error logic.


## OpenAPI

````yaml POST /v1/buy
openapi: 3.1.0
info:
  title: LaserSell API
  version: 1.0.0
  description: >
    The LaserSell API builds unsigned Solana transactions for buying and selling
    tokens across supported DEXs.

    All transactions are non-custodial: the API returns unsigned
    `VersionedTransaction` payloads that you sign locally with your own keypair.


    Supported markets: Pump.fun, PumpSwap, Raydium (CPMM, Launchpad), Meteora
    (DBC, DAMM v2).
servers:
  - url: https://api.lasersell.io
    description: Production
security:
  - apiKey: []
tags:
  - name: Trading
    description: Build unsigned buy and sell transactions.
  - name: Account
    description: Account details and trade history.
  - name: Wallets
    description: Wallet registration for the Exit Intelligence Stream.
paths:
  /v1/buy:
    post:
      tags:
        - Trading
      summary: Build Buy Transaction
      description: >
        Build an unsigned buy transaction to swap SOL or USD1 for tokens via one
        of the supported DEXs.


        The response contains a base64-encoded unsigned `VersionedTransaction`.
        Sign it locally with your keypair and submit it to the network.
      operationId: buildBuyTx
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/BuildBuyTxRequest'
      responses:
        '200':
          description: Unsigned buy transaction built successfully.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BuildTxResponse'
        '400':
          description: >-
            Bad request (invalid parameters, invalid mint, or unsupported token
            program).
          content:
            application/json:
              schema:
                oneOf:
                  - $ref: '#/components/schemas/ErrorResponse'
                  - $ref: '#/components/schemas/UnsupportedResponse'
        '401':
          description: Unauthorized. Missing or invalid API key.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '404':
          description: Unsupported market or mint not indexed yet.
          content:
            application/json:
              schema:
                oneOf:
                  - $ref: '#/components/schemas/UnsupportedResponse'
                  - $ref: '#/components/schemas/NotIndexedResponse'
        '422':
          description: Valid request but no viable route found.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '429':
          description: Rate limited. Back off and retry.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          description: Internal server error.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
components:
  schemas:
    BuildBuyTxRequest:
      type: object
      required:
        - mint
        - user_pubkey
        - slippage_bps
      properties:
        mint:
          type: string
          description: Token mint address to buy (base58).
          example: EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v
        user_pubkey:
          type: string
          description: Your wallet public key (base58).
          example: 9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM
        amount:
          type: number
          description: >
            Human-readable amount to spend (e.g., `0.1` for 0.1 SOL, `10.0` for
            10 USD1).

            Mutually exclusive with `amount_in_total`. Exactly one of `amount`
            or `amount_in_total` must be provided.
          example: 0.1
        amount_in_total:
          type: integer
          description: >
            Amount to spend in input-asset atomic units (e.g., lamports for
            SOL).

            Mutually exclusive with `amount`. Exactly one of `amount` or
            `amount_in_total` must be provided.
          example: 100000000
        slippage_bps:
          type: integer
          description: Maximum slippage tolerance in basis points (e.g., `2000` = 20%).
          example: 2000
        input:
          type: string
          enum:
            - SOL
            - USD1
          default: SOL
          description: Input asset.
        mode:
          type: string
          enum:
            - fast
            - secure
          default: fast
          description: Routing mode hint.
        send_mode:
          type: string
          enum:
            - helius_sender
            - astralane
            - rpc
          description: Transaction send mode.
        tip_lamports:
          type: integer
          description: Optional priority fee tip in lamports.
        partner_fee_recipient:
          type: string
          description: Partner fee recipient wallet (base58 pubkey).
        partner_fee_bps:
          type: integer
          description: >-
            Partner fee in basis points (max 50 = 0.5%). Mutually exclusive with
            `partner_fee_lamports`.
          maximum: 50
        partner_fee_lamports:
          type: integer
          description: >-
            Partner fee as flat SOL lamports (max 50,000,000). Mutually
            exclusive with `partner_fee_bps`.
          maximum: 50000000
    BuildTxResponse:
      type: object
      required:
        - tx
      properties:
        tx:
          type: string
          description: >-
            Base64-encoded unsigned Solana `VersionedTransaction`. Sign this
            locally with your keypair before submitting.
          example: AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA...
        route:
          type: object
          description: Routing metadata.
          properties:
            market_type:
              type: string
              description: DEX used for this route.
              example: pumpswap
            pool_id:
              type: string
              description: Pool address used.
        debug:
          type: object
          description: Debug information (included when available).
    ErrorResponse:
      type: object
      required:
        - error
      properties:
        error:
          type: string
          description: Human-readable error message.
          example: invalid mint address
    UnsupportedResponse:
      type: object
      required:
        - status
        - reason
        - message
      properties:
        status:
          type: string
          const: unsupported
        reason:
          type: string
          enum:
            - no_route
            - invalid_mint
            - unsupported_token_program
          description: Machine-readable reason code.
        message:
          type: string
          description: Human and AI-readable explanation.
          example: >-
            No supported market found for this mint. Supported DEXs: PumpSwap,
            Raydium (CPMM, Launchpad), Meteora (DBC, DAMM v2), Pump.fun.
    NotIndexedResponse:
      type: object
      required:
        - status
        - mint
        - reason
      properties:
        status:
          type: string
          const: not_indexed
        mint:
          type: string
          description: The mint address that is not yet indexed.
        reason:
          type: string
          example: mint not indexed yet; try again shortly
  securitySchemes:
    apiKey:
      type: apiKey
      in: header
      name: x-api-key
      description: >-
        Your LaserSell API key. Obtain one from the [LaserSell
        dashboard](https://www.lasersell.io).

````