Register Class

Developers can register new users under their account, which allows you to credit the rewards earned by your users directly to them. Use the Register class to handle the registration process.

import { Register } from "cash-captcha";

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

const register = new Register(apiKey, claimKey, config);

async function registerNewUser(email, referredBy = "") {
  const result = await register.registerUser(email, referredBy);
  console.log("New User Registered:", result);
}

// Example: Register a new user
registerNewUser("[email protected]", "your-referral-code"); 

// Resposne:
// {
//  "email": "[email protected]",
//  "apiKey": "generated-user-api-key"
//}

Generating a Claim Key for a New User

Once a user is registered, you can generate a new claim key for them. This allows the user to claim their rewards independently.

async function generateClaimKeyForUser(userApiKey) {
  const result = await register.resetClaimKey(userApiKey);
  console.log("New Claim Key Generated:", result.newClaimKey);
}

// Example: Generate a claim key for the new user
generateClaimKeyForUser("new-user-api-key"); 

// Response:
// {
//  "newClaimKey": "generated-claim-key"
// }

It is recommended to leave the "claim key" functionality off unless you have a specific purpose for enabling it. This key grants access to withdrawing all rewards your user has earned and it is your responsibility to ensure it remains a secret.

Last updated