> For the complete documentation index, see [llms.txt](https://gramhal.gitbook.io/bolbhav/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gramhal.gitbook.io/bolbhav/chapter-1-database/wallets-data/user_wallets.md).

# user\_wallets

### Modal

| Field                 | Type      | Nullable | Constraints                          |
| --------------------- | --------- | -------- | ------------------------------------ |
| id                    | varchar   | NO       |                                      |
| user\_id              | int4      |          | <p>Foreign key<br>(person table)</p> |
| balance               | int8      | NO       |                                      |
| wallet\_for           | varchar   | NO       |                                      |
| version\_id           | int4      | NO       |                                      |
| created\_at           | timestamp |          |                                      |
| updated\_at           | timestamp |          |                                      |
| balance\_unit         | varchar   | NO       |                                      |
| date\_of\_transaction | timestamp |          |                                      |

### Description of fields

#### id

This is the a unique identifier of the user wallet.

#### user\_id

The id of the user to which this wallet belongs to.

{% hint style="info" %}
There are 4 entries where user id is set to NULL. Details about those wallets are mentioned at the end of this document under [Bank Wallets](#bank-wallets).
{% endhint %}

#### balance

The current balance amount in the wallet. This value is multiple of 1000 when balance\_unit field is set to token.

#### wallet\_for

This represents the wallet type for the user. Each user can have four wallets:

1. membership - This denotes that the wallet type is membership wallet. The balance field will be considered as the token amount available in the membership wallet. The tokens are credited to this wallet when a user purchases a membership plan and debited when a user views the sale receipts data (once per day).
2. rewards - This denotes that the wallet type is rewards wallet. The balance field will be considered as the token amount available in the reward wallet. The balance is credited to this wallet when a user receives a reward and debited when a user redeems reward tokens.
3. payback - This denotes the payback wallet for the user. The balance field will be considered as the total amount paid back to the user.

#### version\_id

This is a custom field that copies the value from inbuilt postgres index about the number of times a row has been modified. Each operation that leads to a modification in a user wallet row increments this value by 1.

{% hint style="info" %}
The exact intent of this field is yet to be identified. This field may help analyse how many changes are being made to a user wallet. The primary change would be the credit/debit to the wallet balance amount to see which wallets are more active.
{% endhint %}

#### created\_at

Timestamp on which the wallet entry is created.

#### updated\_at

Timestamp on which the wallet entry is last updated.

#### balance\_unit

This represents the wallet balance unit amount. Default value is `token`. For payback wallet, this is set to INR. If the balance is 10000 and balance\_unit is token, it means user has 10 tokens in their wallet. However, if the balance is 10000 and balance\_unit is INR, the wallet holds 10000 INR.

### Bank Wallets

Bolbhav follows a fundamental rule during all wallet transactions that every transaction must have a source and target. It means that if a wallet is being credited an amount, the same amount must be debited from another wallet. Consider a simple payment that when you transfer some money to your friend, your bank account is debited and your friend's bank account is credited. The same philosophy is applied here.

We utilise a concept of bank wallets. There are 4 types of bank wallets:

1. Membership wallet
2. External wallet
3. Reward wallet
4. Payback wallet

Each bank wallet is stored in `user_wallets` table but they do not have a user\_id associated with them. The bank wallets hold the same information as the user wallet, meaning the balance, wallet\_for, balance\_unit etc.

The bank wallets work in the following ways:

1. **Membership wallet** - This wallet started with an initial balance of 10,000,000 (10 million) tokens. When a user purchases a plan, the tokens are credited to their membership wallet and debited from the bank membership wallet.
2. **External wallet** - This wallet simply holds the total amount ever paid by a user. When a user purchases a plan, the `payable_amount` field value is added to this wallet balance. This represents the total amount paid to Bolbhav by users. It represents INR value and contains a multiple of 1000.
3. **Reward wallet** - Similar to membership wallet, this started with an initial balance of 10 million tokens. When a user is rewarded, the tokens are credited to their reward wallet and debited from bank reward wallet.
4. **Payback wallet** - This wallet started with an initial balance of 10 million INR. When a user is paid back, the amount is credited to their payback wallet and debited from bank payback wallet.

{% hint style="warning" %}
The external wallet entry has balance\_unit set to "token" which looks incorrect as it represents the actual INR value contribution.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://gramhal.gitbook.io/bolbhav/chapter-1-database/wallets-data/user_wallets.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
