# StakeERC20

The [StakeERC20 (Or TokenStake) smart contract](https://dexappbuilder.dexkit.com/forms/deploy/thirdweb/TokenStake) from Thirdweb enables users to stake their ERC-20 tokens and receive ERC-20 tokens as rewards for their staking activities (distinct from the staked tokens). The contract administrator must specify the addresses for both the Staking and Reward tokens during deployment, and these addresses cannot be modified subsequently.

Staked tokens are securely held within the contract, and rewards are calculated based on the duration for which these tokens were staked. The administrator is responsible for maintaining an adequate balance of reward tokens within the staking contract. These accumulated rewards are then transferred to stakers upon making a claim.

The calculation for rewards when they are claimed is as follows:

`rewardsPerTokenStaked = ((stakingDuration * rewardRatioNumerator) / rewardRatioDenominator) / timeUnit`

For instance, if the reward ratio is 1/20, this means that 1 Reward token will be distributed for every 20 tokens staked. The numerator and denominator of the reward ratio should be set separately (in this case, 1 and 20, respectively).

## Important points to note

* Users are required to grant approval for their tokens to be used by the staking contract address before staking them.
* The contract administrator should ensure an adequate balance of Reward Tokens in the staking contract and utilize the deposit function for depositing reward tokens.

## Usecases for this contract

* **DeFi Staking Platform:** The contract could be used in a decentralized finance (DeFi) platform where users can stake various ERC-20 tokens to earn rewards. For example, users might stake stablecoins like DAI or USDC to earn governance tokens.
* **Liquidity Provision:** Liquidity providers on decentralized exchanges (DEXs) could use this contract to stake their tokens in liquidity pools. They would receive rewards in a different token, incentivizing liquidity provision.
* **Token Lockup for Voting:** Projects conducting on-chain governance could require users to lock up their tokens using this contract to participate in voting. As a reward, they receive governance tokens that give them voting power.
* **Gaming Rewards:** In blockchain-based games, players could stake in-game assets to earn rare items or tokens. This contract would handle the staking and reward distribution.
* **Content Creation Rewards:** Content platforms could use this contract to reward content creators and curators. Users could stake tokens to promote content, and they receive tokens as rewards based on the success of their promotion.
* **Token Farming:** This contract can be part of a token farming mechanism where users stake tokens to farm new tokens. For instance, they stake a project's native token and earn a new utility token.
* **Staking Pools for Validators:** In proof-of-stake (PoS) or delegated proof-of-stake (DPoS) blockchain networks, validators or delegates could use this contract to reward their stakers with tokens they earn from block validation.
* **NFT Staking:** Users could stake non-fungible tokens (NFTs) in this contract to gain access to exclusive content or experiences. Rewards might include other NFTs, tokens, or digital collectibles.
* **Token Vesting:** Projects can use this contract for token vesting schedules, where team members or investors lock up their tokens and receive them gradually over time as a reward for their commitment.
* **Charitable Donations:** Charities could use this contract to allow donors to stake tokens for a period, and in return, donors receive tokens that can be donated to other charitable causes.

## Deploying this contract

{% embed url="<https://dexappbuilder.dexkit.com/forms/deploy/thirdweb/TokenStake>" %}
Direct link
{% endembed %}

<figure><img src="/files/jXOLGQgRKsUbNlFUdex4" alt=""><figcaption></figcaption></figure>

1. **Name:**
   * **Input:** \[Enter Contract Name]
2. **Description:**
   * **Input:** \[Enter Contract Description]
3. **Reward Token:**
   * **Input:** \[Address of ERC20 token to be used as staking reward]
   * **Explanation:** Designates the ERC20 token that users will receive as rewards for staking their tokens. Admins maintain the balance of these reward tokens in the staking contract.
4. **Staking Token:**
   * **Input:** \[Address of ERC20 tokens that will be staked by users]
5. **Time Unit (in seconds):**
   * **Input:** \[Enter time unit in seconds]: Defines the time unit in seconds for reward distribution. For example, if rewards are distributed per hour, enter 3600 seconds as the time unit.
6. **Reward Ratio Numerator:**
   * **Input:** \[Enter numerator for reward ratio]: Sets the numerator of the reward ratio, indicating the number of reward tokens given for a specific amount of staked tokens (e.g., 1 in a ratio of 1/20).
7. **Reward Ratio Denominator:**
   * **Input:** \[Enter denominator for reward ratio]: Sets the denominator of the reward ratio, defining the total amount of staked tokens required to earn one reward token (e.g., 20 in a ratio of 1/20).


---

# Agent Instructions: 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://docs.dexkit.com/defi-products/dexcontracts/thirdweb-contracts/stakeerc20.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.
