# Rewards Class

The `Rewards` class provides methods to interact with the reward system, including fetching rewards info, viewing rewards history, and claiming rewards.

### Displaying Rewards

You can retrieve your rewards information (pending rewards, available rewards, and total rewards earned) using the `info()` method of the `Rewards` class.

{% tabs %}
{% tab title="JavaScript" %}

```javascript
import { Rewards } from "cash-captcha";

const apiKey = "your-api-key-here";
const claimKey = "your-claim-key-here";
const config = { apiUrl: "https://api.cashcaptcha.com" };

const rewards = new Rewards(apiKey, claimKey, config);

async function fetchRewardsInfo() {
  const info = await rewards.info();
  console.log("Rewards Info:", info);
}

fetchRewardsInfo();

// Response:
// {
//  "rewardsPending": 192249,
//  "rewardsAvailable": 35264,
//  "rewardsEarned": 227513,
//  "rewardsClaimed": 0
// }
```

{% endtab %}
{% endtabs %}

### Rewards History

You can also retrieve the rewards history for a specific epoch using the `history()` method. This returns details such as pool rewards, cumulative difficulty, and the best solution difficulty.

{% tabs %}
{% tab title="JavaScript" %}

<pre class="language-javascript"><code class="lang-javascript">async function fetchRewardsHistory(epoch, page = 0, itemsPerPage = 10) {
  const history = await rewards.history(epoch, page, itemsPerPage);
  console.log("Rewards History:", history);
}

fetchRewardsHistory(8); // Example: Fetch history for Cash Captcha's epoch #8

// Response:
// {
//  "results": [
<strong>//    {
</strong><strong>//      "pool": "group_2",
</strong>//      "pool_best_solution_difficulty": 11,
//      "pool_rewards_earned": 928,
//      "user_rewards_earned": 743,
//      "submission_time": "2024-10-01T13:05:00Z"
//    },
//    ...
//  ],
//  "total": 409
// }
</code></pre>

{% endtab %}
{% endtabs %}

### Claiming Rewards

To claim rewards, use the `claim()` method. You need to provide the amount of ORE to claim, the withdrawal token (SOL, USDC, or ORE), and the withdrawal address.

Make sure you have [generated a claim key](/advanced-usage/advanced-settings.md) in your account settings on the [Cash Captcha website](https://cashcaptcha.com/).

{% tabs %}
{% tab title="JavaScript" %}

<pre class="language-javascript"><code class="lang-javascript">async function claimRewards(amount, withdrawalToken, withdrawalAddress) {
  const result = await rewards.claim(
    amount,
    withdrawalToken,
    withdrawalAddress
  );
  console.log("Claim Result:", result);
}
// Example: Claim 0.0001 ORE and swap it to SOL at the current market rate
claimRewards(10000000, "SOL", "your-wallet-address-here"); 

// Response:
// {
<strong>//  "status": "inProgress"
</strong>// }
</code></pre>

{% endtab %}
{% endtabs %}


---

# 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.cashcaptcha.com/advanced-usage/rewards-class.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.
