> For the complete documentation index, see [llms.txt](https://docs.bemo.fi/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.bemo.fi/developers/bemo-v1-deprecated/stake.md).

# Stake

#### Overview

In **Financial** contract there is an op-code `OP::SIMPLE_TRANSFER`. It's used to perform staking of GRAM in the contract, resulting in the creation of a corresponding amount of stGRAM in exchange for the staked GRAM. The current pools of stGRAM and GRAM are taken into account, allowing the calculation of the amount of stGRAM to be created dynamically. If the operation is successful, the total supply of stGRAM and GRAM is updated, and the newly minted stGRAM jettons are sent to the user's wallet address.

* `OP::SIMPLE_TRANSFER`: Calls the mint function with a `query_id` of `0`. It is a simple invocation that doesn’t pass any extra data.

When a user stakes a certain amount of GRAM, the number of stGRAM to be minted is determined based on the existing stGRAM and GRAM pools.

The number of stGRAM minted is calculated using the formula:&#x20;

`stake_jetton_amount = jetton_total_supply * stake_ton_amount / ton_total_supply`

Where:

* `jetton_total_supply` is the total supply of stGRAM jettons before staking.
* `ton_total_supply` is the total amount of staked GRAM before the staking operation.
* `stake_ton_amount` is the amount of GRAM to be staked after subtracting any relevant fees (`int stake_ton_amount = msg_value - DEPOSIT_PROCESSING_FEE` .

#### Steps to verify the result of staking operation:

To ensure the staking operation was executed correctly, follow these steps:

1. **Check the updated stGRAM and GRAM total supply in the Financial contract:**

* Verify that the `jetton_total_supply` has increased by the calculated `stake_jetton_amount`.
* Ensure that the `ton_total_supply` has increased by `stake_ton_amount`.

2. **Confirm the transfer of stGRAM:**

* The minted stGRAM should be sent to the user’s jetton wallet address. Verify that the correct amount was transferred.
* The transaction should use the `OP::INTERNAL_TRANSFER`, and the `query_id` be `0`.

**Common errors that may occur during processing `OP::SIMPLE_TRANSFER`**

When performing operations in a smart contract, various errors can occur due to incorrect input, insufficient funds, or other issues. To handle these errors effectively, it’s important to understand what kind of errors might arise, how to catch them, and how to determine the underlying issue. Below is a detailed guide on common errors, how to detect them, and troubleshooting strategies.

1. `ERROR::INSUFFICIENT_MSG_VALUE`
   * **Cause**: This error occurs when the provided message value is less than the required amount to perform the operation. Message value must be greater than 0.05 GRAM (`DEPOSIT_PROCESSING_FEE)` .
   * **How to Detect**: Check if the contract throws this error when the condition `msg_value - DEPOSIT_PROCESSING_FEE <= 0` is true.
   * **Troubleshooting**: Ensure that the amount sent in the transaction is enough to cover the required fees and the intended operation.
2. `ERROR::NOT_WORKCHAIN`
   * **Cause**: This error happens when the message is sent from a non-basechain workchain (i.e., not workchain 0). The contract may be designed to only accept transactions from the main chain.
   * **How to Detect**: The contract checks if the sender’s workchain is not equal to 0 and throws this error if true.
   * **Troubleshooting**: Ensure that the transaction is being sent from the basechain (workchain = 0). Verify the sender address and ensure that it matches the expected workchain for the operation.

#### Example of sending stake message using pytoniq:

So, to create a payload cell you need to provide the following params:

* `OP::SIMPLE_TRANSFER` (`0`) - The operation code indicating the type of operation. Represented by a 32-bit unsigned integer

Or you can just send GRAM attached to the empty message to the **Financial** contract

**Let's write a simple code that builds payload cell and sends message to Financial:**

```
from pytoniq import WalletV4R2, LiteBalancer, begin_cell
import asyncio
mnemonics = ["your", "mnemonics", "here"]

async def main():
    provider = LiteBalancer.from_mainnet_config(1)
    await provider.start_up()

    OP_SIMPLE_TRANSFER = 0

    FINANCIAL_ADDRESS = "EQDNhy-nxYFgUqzfUzImBEP67JqsyMIcyk2S5_RwNNEYku0k"

    stake_msg = begin_cell()\
        .store_uint(OP_SIMPLE_TRANSFER, 32)\
    .end_cell()

    ton_to_stake = 100  # example value
    wallet = await WalletV4R2.from_mnemonic(provider=provider, mnemonics=mnemonics)
    await wallet.transfer(destination=FINANCIAL_ADDRESS,
                          amount=int(ton_to_stake*1e9),
                          body=stake_msg)

    await provider.close_all()

asyncio.run(main())
```


---

# 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, and the optional `goal` query parameter:

```
GET https://docs.bemo.fi/developers/bemo-v1-deprecated/stake.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
