npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

stake-ts

v1.0.1

Published

Unofficial TypeScript API wrapper for Stake.com with Cloudflare bypass & full typings

Readme

StakeAPI (stake-ts)

npm version License: MIT TypeScript Node.js Bun

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 import and require() 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 using syntax.

📦 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:

  1. Open Stake.com in your web browser and log in.
  2. Open Developer Tools (F12) $\to$ Network tab $\to$ filter by graphql.
  3. Right-click any GraphQL request $\to$ Copy as cURL or Copy request headers.
  4. Save the cookies into a file named cookie.txt (or pass the cookie string directly to cookies: "...").
  5. Copy your browser's exact User-Agent string and provide it via the userAgent option.
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.