> ## 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.

# Exchange to Credits

> Exchanges the supported stablecoin tokens to Based Credits tokens at 1:1 ratio

<Note>
  This is a smart contract write 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 POST /contracts/exchanger/exchangeToCredits
openapi: 3.0.3
info:
  title: Based Exchanger Smart Contracts API
  description: >-
    OpenAPI specification for the Based Exchanger smart contracts system
    including the main Exchanger contract
  version: 1.0.0
  license:
    name: Proprietary
servers:
  - url: https://mainnet.base.org
    description: Base Mainnet (default RPC endpoint)
security: []
tags:
  - name: Exchange Operations
    description: Core token exchange functionality
  - name: Admin Operations
    description: Administrative functions requiring ADMIN_ROLE
  - name: Treasury Operations
    description: Treasury management functions requiring DEFAULT_ADMIN_ROLE
  - name: View Functions
    description: Read-only functions for querying contract state
  - name: Test Operations
    description: Functions available only in test contracts
paths:
  /contracts/exchanger/exchangeToCredits:
    post:
      tags:
        - Exchange Operations
      summary: Exchange the supported stablecoin to Based Credits
      description: >-
        Exchanges the supported stablecoin tokens to Based Credits tokens at 1:1
        ratio
      operationId: exchangeToCredits
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ExchangeRequest'
      responses:
        '200':
          description: Exchange successful
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TransactionResponse'
        '400':
          description: Invalid request - amount cannot be zero or contract is paused
        '500':
          description: Transaction failed - insufficient balance or transfer failure
components:
  schemas:
    ExchangeRequest:
      type: object
      required:
        - amount
      properties:
        amount:
          type: string
          description: Amount of tokens to exchange (in wei/smallest unit)
          example: '1000000000000000000'
    TransactionResponse:
      type: object
      properties:
        transactionHash:
          type: string
          pattern: ^0x[a-fA-F0-9]{64}$
          description: Transaction hash
          example: '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef'
        blockNumber:
          type: integer
          description: Block number where transaction was mined
          example: 12345678
        gasUsed:
          type: string
          description: Gas used for the transaction
          example: '21000'
        events:
          type: array
          items:
            $ref: '#/components/schemas/Event'
    Event:
      type: object
      properties:
        name:
          type: string
          description: Event name
        args:
          type: object
          description: Event arguments
          additionalProperties: true

````