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.
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
// }
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.
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": [
// {
// "pool": "group_2",
// "pool_best_solution_difficulty": 11,
// "pool_rewards_earned": 928,
// "user_rewards_earned": 743,
// "submission_time": "2024-10-01T13:05:00Z"
// },
// ...
// ],
// "total": 409
// }
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 in your account settings on the Cash Captcha website.
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:
// {
// "status": "inProgress"
// }
Last updated