Getting Started
Polys is an unofficial TypeScript toolkit for building applications on top of the Polymarket API. It provides three main packages that you can use independently or together:
- @dicedhq/polymarket - Typescript client combining both CLOB and Gamma APIs
- @dicedhq/clob - TypeScript client for the CLOB (order book) API
- @dicedhq/gamma - TypeScript client for the Gamma (market data) API
Installation
Section titled “Installation”npm install @dicedhq/polymarket viemyarn add @dicedhq/polymarket viempnpm add @dicedhq/polymarket viembun add @dicedhq/polymarket viemCheck out the Installation Guide for more detailed instructions.
Quick Start
Section titled “Quick Start”Using the Polymarket Client
Section titled “Using the Polymarket Client”import { Polymarket, createConnectedWallet } from "@dicedhq/polymarket";import type { Credentials } from "@dicedhq/polymarket";
// Create a wallet for signing transactionsconst wallet = createConnectedWallet({ privateKey: process.env.PRIVATE_KEY, chain: "polygon",});
// Set up credentials for authenticated endpointsconst credentials: Credentials = { key: process.env.POLYMARKET_API_KEY, secret: process.env.POLYMARKET_SECRET, passphrase: process.env.POLYMARKET_PASSPHRASE,};
// Initialize the clientconst client = new Polymarket({ clob: { wallet, credentials, },});
// Access CLOB APIconst markets = await client.clob.market.list();
// Access Gamma APIconst events = await client.gamma.event.list({ limit: 10 });Using the CLOB client
Section titled “Using the CLOB client”import { Clob, createConnectedWallet } from "@dicedhq/clob";import type { Credentials } from "@dicedhq/clob";
const wallet = createConnectedWallet({ privateKey: process.env.PRIVATE_KEY, chain: "polygon",});
const credentials: Credentials = { key: process.env.POLYMARKET_API_KEY, secret: process.env.POLYMARKET_SECRET, passphrase: process.env.POLYMARKET_PASSPHRASE,};
const client = new Clob({ wallet, credentials,});
// Create and post an orderconst order = await client.order.createOrder({ price: 0.5, side: "BUY", size: 10, tokenId: "your-token-id", expiration: 1000000000, taker: "public",});Using the Gamma Client
Section titled “Using the Gamma Client”import { Gamma } from "@dicedhq/gamma";
// No authentication required for read-only accessconst client = new Gamma();
// Get current active marketsconst markets = await client.market.listCurrent({ limit: 10 });
// Get sports informationconst sports = await client.sport.list();Builder Program & Order Attribution
Section titled “Builder Program & Order Attribution”If you’re part of the Polymarket Builder Program, use the signing server to attribute orders to your account and earn rebates on trading volume.
import { Polymarket, createConnectedWallet } from "@dicedhq/polymarket";
const wallet = createConnectedWallet({ privateKey: process.env.PRIVATE_KEY, chain: "polygon",});
const credentials = { key: process.env.POLYMARKET_API_KEY, secret: process.env.POLYMARKET_SECRET, passphrase: process.env.POLYMARKET_PASSPHRASE,};
// Configure client to use signing serverconst client = new Polymarket({ clob: { wallet, credentials, attributor: { url: "https://your-signing-server.com/api/sign", token: process.env.SIGNING_SERVER_TOKEN, }, },});Benefits:
- Earn Rebates: Attribute orders to your Builder Program account
- Security: Builder credentials never exposed in client code
- Performance: Built with Bun for high-throughput order signing
- Easy deployment: Simple Docker setup for production
Learn more about setup and deployment in the Order Attribution Guide.
Environment Variables
Section titled “Environment Variables”For security, store sensitive credentials in environment variables:
# .env filePRIVATE_KEY=your_wallet_private_keyPOLYMARKET_API_KEY=your_api_keyPOLYMARKET_SECRET=your_api_secretPOLYMARKET_PASSPHRASE=your_passphrase
# For production with signing serverSIGNING_SERVER_TOKEN=your_secure_bearer_tokenNext Steps
Section titled “Next Steps”- Production Setup: Set up Order Attribution for Builder Program rebates
- API Reference: Learn about CLOB API for trading operations
- Market Data: Explore Gamma API for market data
- Best Practices: Check out the error handling guide
- Examples: See code examples in the repository