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

# USD to Tokens

> Calculate how many tokens will be received for a given USD amount

<Note>
  This is a smart contract view function. The curl example shown is for illustration. To call this function, use web3 libraries (ethers.js, viem, web3.py) or JSON-RPC directly.
</Note>


## OpenAPI

````yaml GET /market/{marketAddress}/usdToTokens
openapi: 3.0.3
info:
  title: Based Protocol Smart Contracts API
  description: >-
    OpenAPI specification for the Based Protocol - a bidirectional perpetual
    markets platform built for EVM blockchains. The protocol allows users to
    create binary markets where participants can take "Based" (positive) or
    "Cringe" (negative) positions using the Based Market mechanism.
  version: 1.0.0
  license:
    name: LicenseRef-Proprietary
servers:
  - url: https://mainnet.base.org
    description: Base Mainnet (default RPC endpoint)
security: []
tags:
  - name: BasedProtocol
    description: Operations related to the main protocol contract
  - name: BasedMarket
    description: Operations for individual markets
  - name: BasedMarketRouter
    description: Router operations with safety checks and deadline protection
paths:
  /market/{marketAddress}/usdToTokens:
    get:
      tags:
        - BasedMarket
      summary: Calculate USD to tokens conversion
      description: Calculate how many tokens will be received for a given USD amount
      operationId: getUsdToTokens
      parameters:
        - name: marketAddress
          in: path
          required: true
          schema:
            type: string
            pattern: ^0x[a-fA-F0-9]{40}$
          description: Address of the market contract
        - name: amountIn
          in: query
          required: true
          schema:
            type: integer
            format: uint256
            minimum: 1
          description: USD amount to convert
        - name: buyBased
          in: query
          required: true
          schema:
            type: boolean
          description: True if buying Based, false if buying Cringe
      responses:
        '200':
          description: Conversion calculated successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UsdToTokensResponse'
components:
  schemas:
    UsdToTokensResponse:
      type: object
      properties:
        tokensIn:
          type: integer
          format: int64
          description: Tokens deposited to AMM
        tokensOut:
          type: integer
          format: int64
          description: Tokens received from AMM
        protocolFeeAmount:
          type: integer
          format: uint256
          description: Protocol fee amount
        creatorFeeAmount:
          type: integer
          format: uint256
          description: Creator fee amount

````