Constants

SDK constants including API URLs, token mints, and defaults

Constants

The SDK exports various constants for API endpoints, token addresses, and default values.

Import

import {
  // API URLs (default to development)
  METADATA_API_BASE_URL,
  TRADE_API_BASE_URL,
  WEBSOCKET_URL,
 
  // Production API URLs
  PROD_METADATA_API_BASE_URL,
  PROD_TRADE_API_BASE_URL,
  PROD_WEBSOCKET_URL,
 
  // Deprecated - use base URLs instead
  DEV_METADATA_API_BASE_URL,
  DEV_TRADE_API_BASE_URL,
  DEV_WEBSOCKET_URL,
 
  // Token mints
  USDC_MINT,
  SOL_MINT,
 
  // Trading defaults
  DEFAULT_SLIPPAGE_BPS,
  OUTCOME_TOKEN_DECIMALS,
 
  // Limits
  MAX_BATCH_SIZE,
  MAX_FILTER_ADDRESSES,
} from 'dflow-sdk';

API URLs

Default (Development)

These are the default URLs used when no environment is specified:

ConstantValueDescription
METADATA_API_BASE_URLhttps://dev-prediction-markets-api.dflow.net/api/v1Development metadata API. No API key required.
TRADE_API_BASE_URLhttps://dev-quote-api.dflow.netDevelopment trade API. No API key required.
WEBSOCKET_URLwss://dev-prediction-markets-api.dflow.net/api/v1/wsDevelopment WebSocket. No API key required.

Production

ConstantValueDescription
PROD_METADATA_API_BASE_URLhttps://prediction-markets-api.dflow.net/api/v1Production metadata API. Requires API key.
PROD_TRADE_API_BASE_URLhttps://quote-api.dflow.netProduction trade API. Requires API key.
PROD_WEBSOCKET_URLwss://prediction-markets-api.dflow.net/api/v1/wsProduction WebSocket. Requires API key.

Deprecated

These constants are deprecated and will be removed in a future version:

ConstantNote
DEV_METADATA_API_BASE_URLUse METADATA_API_BASE_URL instead
DEV_TRADE_API_BASE_URLUse TRADE_API_BASE_URL instead
DEV_WEBSOCKET_URLUse WEBSOCKET_URL instead

Token Mints

ConstantDescriptionValue
USDC_MINTUSDC token mint on SolanaEPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v
SOL_MINTNative SOL (wrapped) mintSo11111111111111111111111111111111111111112

Trading Defaults

ConstantValueDescription
DEFAULT_SLIPPAGE_BPS50Default slippage tolerance (0.5%)
OUTCOME_TOKEN_DECIMALS6Decimal places for outcome tokens

Limits

ConstantValueDescription
MAX_BATCH_SIZE100Maximum items in batch requests
MAX_FILTER_ADDRESSES200Maximum addresses in filter requests

Usage Examples

Using Development Environment (Default)

import { DFlowClient } from 'dflow-sdk';
 
// Development is the default - no API key required
const dflow = new DFlowClient();
 
// Equivalent to:
const dflow2 = new DFlowClient({ environment: 'development' });

Using Production Environment

import { DFlowClient } from 'dflow-sdk';
 
// Production requires an API key
const dflow = new DFlowClient({
  environment: 'production',
  apiKey: 'your-api-key',
});

Using Custom Endpoints

import {
  DFlowClient,
  PROD_METADATA_API_BASE_URL,
  PROD_TRADE_API_BASE_URL,
  PROD_WEBSOCKET_URL,
} from 'dflow-sdk';
 
// Custom endpoint configuration (overrides environment)
const dflow = new DFlowClient({
  metadataBaseUrl: PROD_METADATA_API_BASE_URL,
  tradeBaseUrl: PROD_TRADE_API_BASE_URL,
  wsOptions: {
    url: PROD_WEBSOCKET_URL,
  },
});

Using Token Mints

import { USDC_MINT, SOL_MINT } from 'dflow-sdk';
 
// Swap USDC for YES tokens
const quote = await dflow.swap.getQuote({
  inputMint: USDC_MINT,
  outputMint: yesMint,
  amount: 1000000,
});
 
// Swap SOL for YES tokens
const solQuote = await dflow.swap.getQuote({
  inputMint: SOL_MINT,
  outputMint: yesMint,
  amount: 100000000, // 0.1 SOL
});

Respecting Batch Limits

import { MAX_BATCH_SIZE } from 'dflow-sdk';
 
async function fetchAllMarkets(tickers: string[]) {
  const allMarkets = [];
  
  // Chunk requests to respect batch limit
  for (let i = 0; i < tickers.length; i += MAX_BATCH_SIZE) {
    const chunk = tickers.slice(i, i + MAX_BATCH_SIZE);
    const markets = await dflow.markets.getMarketsBatch({ tickers: chunk });
    allMarkets.push(...markets);
  }
  
  return allMarkets;
}

Converting Amounts

import { OUTCOME_TOKEN_DECIMALS } from 'dflow-sdk';
 
// Convert human-readable to raw amount
function toRawAmount(humanAmount: number): number {
  return humanAmount * Math.pow(10, OUTCOME_TOKEN_DECIMALS);
}
 
// Convert raw to human-readable
function toHumanAmount(rawAmount: number): number {
  return rawAmount / Math.pow(10, OUTCOME_TOKEN_DECIMALS);
}
 
// Usage
const rawAmount = toRawAmount(100); // 100 tokens → 100000000
const humanAmount = toHumanAmount(50000000); // 50000000 → 50 tokens

On this page