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

polycode-sdk-ts

v1.0.1

Published

TypeScript SDK for PolyCode - prediction markets resolved with code

Readme

PolyCode TypeScript SDK

A comprehensive TypeScript SDK for interacting with the PolyCode API. PolyCode allows you to create prediction markets that are resolved with code.

Features

  • ✅ Create and manage prediction markets
  • ✅ Place and manage bets
  • ✅ Query market and bet information
  • ✅ Resolve markets with code execution results
  • ✅ Full async/await support
  • ✅ Type-safe API with comprehensive error handling
  • ✅ Builder pattern for flexible configuration

Installation

npm install polycode-sdk-ts

Quick Start

Basic Usage

import {
  PolyCodeConfig,
  PolyCodeClient,
  MarketsApi,
  BetsApi,
  CreateMarketRequest,
  PlaceBetRequest,
  MarketStatus,
} from 'polycode-sdk-ts';

async function main() {
  // Configure the client
  const config = new PolyCodeConfig()
    .withBaseUrl('https://api.polycode.com')
    .withApiKey('your-api-key')
    .withTimeout(30);

  const client = new PolyCodeClient(config);

  // Work with markets
  const markets = new MarketsApi(client);

  // Create a market
  const marketRequest: CreateMarketRequest = {
    title: 'Will it rain tomorrow?',
    description: 'Predicting weather for tomorrow',
    resolution_code: 'check_weather_api()',
    code_language: 'python',
    outcomes: ['Yes', 'No'],
  };

  const market = await markets.createMarket(marketRequest);
  console.log('Created market:', market.id);

  // List open markets
  const response = await markets.listMarkets(MarketStatus.Open, 10, undefined);
  console.log('Found', response.markets.length, 'markets');

  // Get a specific market
  const marketDetails = await markets.getMarket(market.id);
  console.log('Market status:', marketDetails.status);

  // Work with bets
  const bets = new BetsApi(client);

  // Place a bet
  const betRequest: PlaceBetRequest = {
    market_id: market.id,
    outcome: 'Yes',
    amount: 100.0,
    currency: 'USD',
  };

  const bet = await bets.placeBet(betRequest);
  console.log('Placed bet:', bet.id);

  // List bets for a market
  const betResponse = await bets.listBets(market.id, undefined, 10, undefined);
  console.log('Found', betResponse.bets.length, 'bets');
}

main().catch(console.error);

Configuration

The SDK supports flexible configuration through the PolyCodeConfig builder:

import { PolyCodeConfig } from 'polycode-sdk-ts';

const config = new PolyCodeConfig()
  .withBaseUrl('https://api.polycode.com')
  .withApiKey('your-api-key')
  .withTimeout(60)
  .withHeader('X-Custom-Header', 'value');

Error Handling

The SDK provides comprehensive error handling:

import { PolyCodeError } from 'polycode-sdk-ts';

async function example() {
  try {
    const market = await markets.createMarket(request);
    console.log('Success:', market.id);
  } catch (error) {
    if (error instanceof PolyCodeError) {
      if (error.type === 'ApiError') {
        console.error(`API error ${error.status}: ${error.message}`);
      } else if (error.type === 'AuthenticationError') {
        console.error('Auth error:', error.message);
      } else {
        console.error('Error:', error.message);
      }
    } else {
      console.error('Unknown error:', error);
    }
  }
}

API Reference

Markets API

  • createMarket(request) - Create a new prediction market
  • getMarket(id) - Get market by ID
  • listMarkets(status?, limit?, cursor?) - List markets with optional filters
  • resolveMarket(id, request) - Resolve a market with code execution result
  • getMarketResolution(id) - Get resolution details for a market

Bets API

  • placeBet(request) - Place a bet on a market outcome
  • getBet(id) - Get bet by ID
  • listBets(marketId?, userId?, limit?, cursor?) - List bets with optional filters
  • cancelBet(id) - Cancel a bet (if allowed)

Data Models

Market

Represents a prediction market with the following fields:

  • id: Unique identifier
  • title: Market title
  • description: Market description
  • status: Current status (Open, Resolved, Cancelled, Pending)
  • resolution_code: Code that will be executed to resolve the market
  • code_language: Language/runtime for the resolution code
  • outcomes: Possible outcomes
  • created_at: Creation timestamp
  • resolved_at: Resolution timestamp (if resolved)
  • resolved_outcome: The resolved outcome (if resolved)

Bet

Represents a bet placed on a market:

  • id: Unique identifier
  • market_id: ID of the market
  • outcome: The outcome being bet on
  • amount: Bet amount
  • currency: Currency (optional)
  • user_id: User who placed the bet
  • created_at: Creation timestamp
  • status: Bet status (Active, Cancelled, Settled)

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.