---
description: >-
  This page explains the process of using tokens for viewing crop prices in the
  Bolbhav app.
---

# Token Deduction Logic

In the Bolbhav app, users who have purchased tokens can utilize them for viewing crop prices. However, users who have not purchased a yearly plan will need to pay tokens for accessing crop data in any mandi.\
\
\
Endpoint Triggered:

* **Before v6.0.0:** [https://listag.net/api/v1/bolbhav-plus/mandi-crop-data](https://bold-moon-807876.postman.co/workspace/Bolbhav-Android-app~337874ea-5b97-4a7a-85db-3f89368f6cf4/request/27013507-f351d472-b6c6-420c-aec2-b772afd41b46?ctx=documentation)
* **v6.0.0 and higher:** [https://listag.net/api/v1/bolbhav-plus/trader-crop-mandis](https://bold-moon-807876.postman.co/workspace/Bolbhav-Plus-Web-App~3d6d5ad9-1cee-40ef-bdc6-338a6c141f9f/request/27013507-ae8f3c44-5fdd-4d52-a7a4-2363c97b794b?ctx=documentation)

Purpose of this API:

* This API is utilized for accessing crop price data in the Bolbhav app.
* It first verifies if the user is a Bolbhav Plus member. If not, it proceeds to deduct tokens for crop price viewing, unless already deducted.

Token Deduction Logic:

* The API triggers the `reduce_token_for_crop_price_view` function, which verifies whether the user has already viewed crop prices today.
* If the user hasn't viewed crop prices today, it checks if the user has sufficient tokens in their wallet (at least 4 tokens) and if crop prices are available for either today or yesterday.
* If the conditions are met, tokens are deducted from the user's wallet for crop price viewing.

Usage:

* This API is used in versions 6.0.0 and higher for facilitating crop price viewing.
* In versions prior to v6.0.0, a similar API (`mandi-crop-data`) was used, but without the Bolbhav Plus membership verification. Additionally, it had limited crop metrics data and was specific to certain crops and mandis.

### Database transactions

Token Deduction from User Membership Wallet (Silver Token):

* **Source Wallet ID:** The user's membership wallet ID serves as the source of the transaction.
* **Target Wallet ID:** The bank's membership wallet ID is designated as the target for receiving the deducted tokens.
* **Amount:** 4000 tokens are debited from the user's membership wallet, equivalent to 4 tokens. (In the database, tokens are stored as multiples of 1000.)
* **Reason:** The reason field provides context for the transaction, indicating the purpose as the usage for viewing crop receipts. In Hindi, this is represented as "फसल की रसीदें देखीं".
* **Ref ID:** The reference ID stored in the Wallet Ledger table is "crop\_price\_viewed", which helps track the transaction back to its origin.
