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

predictstack-sdk

v0.1.2

Published

Official JavaScript/TypeScript SDK for the PredictStack prediction market platform

Readme

@predictstack/sdk

Official JavaScript / TypeScript SDK for the PredictStack prediction market platform built on Stacks.

Installation

npm install @predictstack/sdk

Quick Start

import { PredictStackClient } from '@predictstack/sdk';

const client = new PredictStackClient({
  baseUrl: 'https://predictstack.onrender.com',
});

// List active markets sorted by volume
const markets = await client.markets.list({ status: 'active', sort: 'volume' });
console.log(markets[0].question);

// Get platform stats
const stats = await client.platform.getStats();
console.log(`Total volume: ${stats.totalVolumeMicro / 1_000_000} STX`);

API Reference

new PredictStackClient(options)

| Option | Type | Description | |--------|------|-------------| | baseUrl | string | Backend URL, e.g. https://predictstack.onrender.com | | timeout | number | Request timeout in milliseconds (default: 30000) | | maxRetries | number | Maximum retry attempts for failed requests (default: 3) | | debug | boolean | Enable debug logging (default: false) |


client.markets

// List markets (all filters optional)
const markets = await client.markets.list({
  status: 'active',           // 'active' | 'resolved' | 'cancelled'
  sort: 'volume',             // 'newest' | 'volume' | 'ending'
  limit: 20,
  creator: 'SP1ABC...',
  dateFrom: '2025-01-01',
  dateTo: '2025-12-31',
});

// Get by on-chain market ID
const market = await client.markets.get(1);

// Get by backend UUID
const market = await client.markets.getById('mkt_abc123');

// Get by market ref slug
const market = await client.markets.getByRef('will-btc-hit-100k');

// Get current yes/no odds (basis points, e.g. 5500 = 55%)
const odds = await client.markets.getOdds(1);
// { yes: 5500, no: 4500 }

// Get slippage preview for a potential bet
const quotes = await client.markets.getQuotes(1);
// { slippagePreview: 0 }

// Get next available market ID from the contract
const nextId = await client.markets.getNextId();

client.bets

Placing a bet is a two-step flow: create an intent → sign on-chain → confirm.

// Step 1: Create bet intent — backend records it and returns contract call details
const intent = await client.bets.createIntent({
  userAddress: 'SP1ABC...',     // user's mainnet STX address
  contractMarketId: 1,
  amountMicro: 50_000,          // 0.05 STX in micro-STX
  outcome: true,                // true = YES, false = NO
});

// intent.contractCall contains everything needed for the wallet:
// { contractAddress, contractName, functionName, args, postConditionAmountMicro }

// Step 2: Pass intent.contractCall to Leather / Xverse wallet for signing
// (wallet-specific — not part of this SDK)
const txId = '0xabc...'; // received from wallet after broadcast

// Step 3: Confirm — backend updates state
const result = await client.bets.confirm({
  betId: intent.betId,
  txId,
});
// { success: true, position: Position }

client.claims

// After calling claim-winnings or claim-refund on-chain via your wallet:
const result = await client.claims.confirm({
  userAddress: 'SP1ABC...',
  contractMarketId: 1,
  txId: '0xabc...',
  type: 'winnings',   // 'winnings' | 'refund' (default: 'winnings')
});
// { success: true, amountMicro: 150000 }

client.users

// Full dashboard: user stats + all positions with market data
const dashboard = await client.users.getDashboard('SP1ABC...');
// { summary: User, positions: [{ market, position }, ...] }

// Single position on a market
const position = await client.users.getPosition('SP1ABC...', 1);
// { yesAmountMicro, noAmountMicro, totalWageredMicro, claimed, ... } | null

// Markets the user has bet on (array of contractMarketId)
const marketIds = await client.users.getMarkets('SP1ABC...');
// [1, 3, 7]

client.platform

// Network / contract configuration
const config = await client.platform.getConfig();
// { network: 'mainnet', contractAddress: 'SP...', contractName: '...', platformFeeMicro: 10000 }

// Global platform statistics
const stats = await client.platform.getStats();
// { totalMarkets, totalVolumeMicro, totalFeesCollectedMicro, totalUsers, activeMarkets }

// Leaderboard (default top 15)
const board = await client.platform.getLeaderboard(10);
// [{ address, totalProfit, winRate, totalBets, rank }, ...]

Error Handling

import { PredictStackClient, PredictStackError } from '@predictstack/sdk';

try {
  const market = await client.markets.get(9999);
} catch (err) {
  if (err instanceof PredictStackError) {
    console.error(err.status);  // e.g. 404
    console.error(err.message); // e.g. 'Market not found'
    console.error(err.body);    // raw response body
  }
}

TypeScript Types

All types are exported from the package root:

import type {
  Market,
  Bet,
  Position,
  Claim,
  User,
  LeaderboardEntry,
  BetIntentPayload,
  BetIntentResponse,
  BetConfirmPayload,
  ClaimConfirmPayload,
  PlatformConfig,
  PlatformStats,
  ListMarketsFilters,
  MarketOdds,
  MarketQuotes,
  UserDashboard,
} from '@predictstack/sdk';

Mainnet vs Testnet

Point baseUrl at whichever backend is deployed:

| Network | URL | |---------|-----| | Mainnet | https://predictstack.onrender.com | | Local dev | http://localhost:4000 |

The SDK itself is network-agnostic — it talks to the backend, which handles the Stacks node connection.


License

MIT