> For the complete documentation index, see [llms.txt](https://docs.cashcaptcha.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cashcaptcha.com/advanced-usage/rewards-class.md).

# 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 %}
