# API Descriptions

The following API functions will facilitate user interactions with the KLIK platform during and after the ICO. These APIs handle everything from the claim process for existing users, new purchases by investors, and management of in-app wallets. Below is a detailed description of each API endpoint:

***

#### **7.1 Claim API**

The **Claim API** allows existing KLIK users to claim their equivalent **Crypto KCs** based on their **In-App KC** balance. This API facilitates the conversion from **In-App KCs** (the in-app currency) to **Crypto KCs** (ERC-20 tokens), ensuring that users can participate in the ICO without needing to navigate complex crypto transactions.

* **Endpoint:**
  * `POST /api/claimKC`
* **Function:**
  * Claims **Crypto KCs** for a given **In-App KC** balance and initiates the token conversion process.
* **Parameters:**
  * `databaseEntryId` (string): The unique identifier representing the user's in-app balance (database entry ID).
  * `userId` (string): The unique identifier for the user within the KLIK platform.
  * `walletAddress` (string): The user's connected wallet (Web3auth) that will receive the converted **Crypto KCs**.
* **Response:**
  * `success` (boolean): Indicates whether the claim was successful.
  * `claimedAmount` (integer): The total amount of **Crypto KCs** claimed.
  * `gasFees` (decimal): The calculated gas fees for the transaction.
  * `transactionHash` (string): The hash of the transaction on the Ethereum network.
* **Example Request:**

  ```json
  jsonCopy code{
    "databaseEntryId": "abc123",
    "userId": "user456",
    "walletAddress": "0xABCDEF123456"
  }
  ```
* **Example Response:**

  ```json
  jsonCopy code{
    "success": true,
    "claimedAmount": 1000,
    "gasFees": 0.005,
    "transactionHash": "0x9876543210abcdef"
  }
  ```

***

#### **7.2 New User API**

The **New User API** enables new users or investors to purchase **Crypto KCs** during the ICO. This API supports both fiat and cryptocurrency purchases, ensuring a smooth onboarding process for users who may not be familiar with crypto transactions.

* **Endpoint:**
  * `POST /api/purchaseKC`
* **Function:**
  * Handles new user purchases of **Crypto KCs** using fiat or cryptocurrency.
* **Parameters:**
  * `amount` (decimal): The amount of **Crypto KCs** the user intends to purchase.
  * `paymentMethod` (string): The method of payment (e.g., "fiat", "crypto").
  * `walletAddress` (string): The user's wallet address (either newly created or existing) to receive the purchased **Crypto KCs**.
* **Response:**
  * `success` (boolean): Indicates whether the purchase was successful.
  * `purchasedAmount` (decimal): The amount of **Crypto KCs** purchased.
  * `transactionHash` (string): The hash of the transaction, if applicable (for crypto purchases).
  * `fiatReceipt` (string): A receipt number or confirmation for fiat purchases.
* **Example Request:**

  ```json
  jsonCopy code{
    "amount": 500,
    "paymentMethod": "fiat",
    "walletAddress": "0x12345abcd56789ef"
  }
  ```
* **Example Response:**

  ```json
  jsonCopy code{
    "success": true,
    "purchasedAmount": 500,
    "fiatReceipt": "fiat123456789"
  }
  ```

***

#### **7.3 In-App KC API**

The **In-App KC API** manages the deposit and withdrawal of **Crypto KCs** into and out of the in-app wallets, giving users full control over their **Crypto KC** holdings.

***

**7.3.1 Deposit API**

This API allows users to deposit **Crypto KCs** into their in-app wallets for use in the KLIK ecosystem. This API ensures that users can transfer external **Crypto KCs** to their in-app wallet for purchases and content access.

* **Endpoint:**
  * `POST /api/depositKC`
* **Function:**
  * Manages deposits of **Crypto KCs** into in-app wallets.
* **Parameters:**
  * `amount` (decimal): The number of **Crypto KCs** to deposit.
  * `walletAddress` (string): The external wallet address from which the **Crypto KCs** will be transferred.
  * `inAppWalletId` (string): The unique identifier for the user's in-app wallet.
* **Response:**
  * `success` (boolean): Indicates whether the deposit was successful.
  * `depositedAmount` (decimal): The total amount deposited into the in-app wallet.
  * `transactionHash` (string): The hash of the transaction on the blockchain.
* **Example Request:**

  ```json
  jsonCopy code{
    "amount": 100,
    "walletAddress": "0xABCDE12345",
    "inAppWalletId": "wallet6789"
  }
  ```
* **Example Response:**

  ```json
  jsonCopy code{
    "success": true,
    "depositedAmount": 100,
    "transactionHash": "0xabcdef123456789"
  }
  ```

***

**7.3.2 Withdraw API**

The **Withdraw API** enables users to withdraw their **Crypto KCs** from the in-app wallet to external wallets or exchanges. This API supports withdrawals to any Ethereum-based wallet.

* **Endpoint:**
  * `POST /api/withdrawKC`
* **Function:**
  * Facilitates withdrawals of **Crypto KCs** from in-app wallets to external wallets.
* **Parameters:**
  * `amount` (decimal): The number of **Crypto KCs** to withdraw.
  * `walletAddress` (string): The external wallet address where the **Crypto KCs** will be sent.
  * `inAppWalletId` (string): The unique identifier for the user's in-app wallet.
* **Response:**
  * `success` (boolean): Indicates whether the withdrawal was successful.
  * `withdrawnAmount` (decimal): The total amount withdrawn from the in-app wallet.
  * `gasFees` (decimal): The calculated gas fees for the transaction.
  * `transactionHash` (string): The hash of the transaction on the blockchain.
* **Example Request:**

  ```json
  jsonCopy code{
    "amount": 50,
    "walletAddress": "0x1234abcd5678ef90",
    "inAppWalletId": "wallet6789"
  }
  ```
* **Example Response:**

  ```json
  jsonCopy code{
    "success": true,
    "withdrawnAmount": 50,
    "gasFees": 0.004,
    "transactionHash": "0xabcdef987654321"
  }
  ```

***

#### **7.4 User Balance API**

This additional API allows users to check their **Crypto KC** balance, both in their in-app wallet and external wallets, giving them clear visibility of their holdings.

**7.4.1 Check Balance API**

* **Endpoint:**
  * `GET /api/checkBalance`
* **Function:**
  * Retrieves the current balance of **Crypto KCs** in both in-app and external wallets.
* **Parameters:**
  * `userId` (string): The unique identifier of the user.
  * `walletAddress` (string): The wallet address associated with the user's account.
* **Response:**
  * `inAppBalance` (decimal): The amount of **Crypto KCs** in the in-app wallet.
  * `externalBalance` (decimal): The amount of **Crypto KCs** in the external wallet.
* **Example Request:**

  ```json
  jsonCopy code{
    "userId": "user123",
    "walletAddress": "0xABCDEF123456789"
  }
  ```
* **Example Response:**

  ```json
  jsonCopy code{
    "inAppBalance": 500,
    "externalBalance": 2000
  }
  ```
