stake-ts
v1.0.1
Published
Unofficial TypeScript API wrapper for Stake.com with Cloudflare bypass & full typings
Maintainers
Readme
StakeAPI (stake-ts)
An unofficial, production-ready TypeScript API wrapper for Stake.com.
Provides full programmatic access to Stake's GraphQL API, with support for user balances, bet history, currency rates, game endpoints (Stake Originals: Mines, Limbo, Dice, Plinko, Slide, Crash, and more), Cloudflare bypass session management, and comprehensive TypeScript types.
⚡ Features
- Full TypeScript Definitions: Strictly typed parameters, return objects, and GraphQL responses.
- Dual Build (ESM + CommonJS): Works out of the box with
importandrequire()in Node.js, Bun, Deno, and modern bundlers. - Cloudflare & Anti-Bot Bypass: Supports session cookie injection (
cf_clearance,session) and browser User-Agent emulation. - Stake Originals: Native helpers for playing Stake Originals games (Mines, Limbo, Slide, Dice, Plinko).
- Domain Mirroring Support: Easily switch to official Stake mirrors (e.g.,
stake.bet,stake1017.com). - Typed Error Hierarchy: Clear exceptions for authentication failures, rate limits, GraphQL errors, and network issues.
- Explicit Resource Management: Full compatibility with the TypeScript
using/await usingsyntax.
📦 Installation
Install via your preferred package manager:
# npm
npm install stake-ts
# pnpm
pnpm add stake-ts
# yarn
yarn add stake-ts
# bun
bun add stake-ts🚀 Quickstart
1. Initialization & Authentication
Authenticate using your Stake session cookie or API accessToken:
import { StakeAPI } from "stake-ts";
const client = new StakeAPI({
// Option A: Pass raw access token or session cookie
accessToken: process.env.STAKE_API_KEY,
// Option B: Pass cookie file (saved from DevTools) for Cloudflare bypass
cookieFile: "cookie.txt",
// Optional: User-Agent matching the browser session
userAgent: process.env.STAKE_USER_AGENT,
// Optional: Use a regional mirror if stake.com is geo-restricted
baseUrl: "https://stake.com", // e.g. "https://stake.bet" or "https://stake1017.com"
});
// Fetch user profile
const user = await client.getUserProfile();
console.log(`Logged in as: ${user.username} (ID: ${user.id})`);
// Fetch balances
const balances = await client.getUserBalance();
console.log("Balances:", balances);
// Always close the client session when done
await client.close();2. Modern Async Disposable (await using)
StakeAPI implements Symbol.asyncDispose, automatically cleaning up resources when exiting scope:
import { StakeAPI } from "stake-ts";
async function checkRates() {
await using client = new StakeAPI({ cookieFile: "cookie.txt" });
const rates = await client.getCurrencyRates();
console.log("Current crypto rates:", rates.baseRates);
}3. Querying Bets & Statistics
import { StakeAPI } from "stake-ts";
const client = new StakeAPI({ cookieFile: "cookie.txt" });
// Retrieve the last 15 bets across all games
const recentBets = await client.getBetHistory(15);
for (const bet of recentBets) {
console.log(`[${bet.game}] Bet: $${bet.amount} | Payout: ${bet.payoutMultiplier}x | Win: ${bet.payout > 0}`);
}
// Retrieve high-roller bets
const highRollers = await client.getHighRollerBets(10);
console.log("High Rollers:", highRollers);
await client.close();4. Playing Stake Originals (e.g. Mines)
The library provides high-level helpers to interact directly with Stake Originals:
import { StakeAPI } from "stake-ts";
const client = new StakeAPI({ cookieFile: "cookie.txt" });
// Play a full Mines round with automatic cashout:
// 7 mines, pick tiles [15, 20], bet $1.00 USDT
const result = await client.playMinesRound(
7, // minesCount
[15, 20], // picked tiles (indices 0 to 24)
1.0, // bet amount (0 for virtual/risk-free test)
"usdt" // currency
);
if (result.won) {
console.log(`✅ WON! Multiplier: ${result.payoutMultiplier}x | Payout: $${result.payout}`);
} else {
console.log(`❌ LOSS! Bomb hit. Revealed mines:`, result.revealedMines);
}
await client.close();🛡️ Error Handling
The package includes a comprehensive, typed error hierarchy:
import {
StakeAPI,
StakeAPIError,
AuthenticationError,
PermissionDeniedError,
RateLimitError,
CloudflareChallengeError,
} from "stake-ts";
try {
const client = new StakeAPI({ cookieFile: "cookie.txt" });
await client.getUserProfile();
} catch (error) {
if (error instanceof AuthenticationError) {
console.error("Session expired or invalid token. Refresh your cookies.");
} else if (error instanceof RateLimitError) {
console.warn(`Rate limited! Retry after ${error.retryAfter} seconds.`);
} else if (error instanceof CloudflareChallengeError) {
console.error("Cloudflare challenge encountered. Refresh cf_clearance cookie.");
} else if (error instanceof StakeAPIError) {
console.error(`Stake API error [${error.code}]:`, error.message);
} else {
console.error("Unexpected error:", error);
}
}🌐 Cloudflare Bypass Configuration
If Stake is protected by Cloudflare anti-bot challenges:
- Open Stake.com in your web browser and log in.
- Open Developer Tools (
F12) $\to$ Network tab $\to$ filter bygraphql. - Right-click any GraphQL request $\to$ Copy as cURL or Copy request headers.
- Save the cookies into a file named
cookie.txt(or pass the cookie string directly tocookies: "..."). - Copy your browser's exact
User-Agentstring and provide it via theuserAgentoption.
const client = new StakeAPI({
cookieFile: "cookie.txt",
userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 ...",
});📄 License
This project is licensed under the MIT License.
⚠️ Disclaimer
This package is an unofficial third-party library and is not affiliated, endorsed, or sponsored by Stake.com or Medium Rare N.V. Use responsibly and adhere to Stake.com's terms of service and applicable local gambling regulations.
