Skip to content

SDK Example Usage: Build Your Own Prediction Market Frontend

Depredict is designed for builders. You can use the SDK to create your own custom prediction market frontend, dApp, or integration. Here's how to get started:

1. Initialize the SDK

import { Connection, PublicKey } from '@solana/web3.js';
import DepredictClient, { MarketType, OracleType } from '@endcorp/depredict';
 
const connection = new Connection('https://api.devnet.solana.com');
const adminKey = new PublicKey('...'); // Your admin public key
const feeVault = new PublicKey('...'); // Your fee vault public key
 
const client = new DepredictClient(connection, adminKey, feeVault);

2. Fetch and Display Markets

const markets = await client.trade.getAllMarkets();
// Render these in your UI

3. Create a New Market

await client.trade.createMarket({
  startTime: Math.floor(Date.now() / 1000),
  endTime: Math.floor((Date.now() + 86400000) / 1000),
  question: 'Will SOL be above $200 by tomorrow?',
  metadataUri: 'https://your-metadata-url',
  payer: adminKey,
  oracleType: OracleType.MANUAL, // or OracleType.SWITCHBOARD
  marketType: MarketType.LIVE, // or MarketType.FUTURE
  // bettingStartTime required for FUTURE markets
});

4. Place a Trade (Open a Position)

await client.trade.openPosition({
  marketId: 1, // The market you want to trade on
  amount: 100, // Amount in market token; decimals auto-handled
  direction: { yes: {} }, // or { no: {} }
  payer: /* user's public key */,
  metadataUri: 'https://your-nft-metadata',
});

5. Settle and Resolve Markets

  • Use resolveMarket to resolve outcomes (admin or oracle)
  • Use payoutPosition for users to claim winnings

6. Reuse Address Lookup Tables for Cheap Claims

// Create a shared LUT for all markets this creator runs
const creatorLut = await client.trade.ensureMarketCreatorLookupTable({
  authority: adminKey,
  payer: adminKey,
});
if (creatorLut.createTx) await sendTx(creatorLut.createTx, [adminSigner]);
for (const extendTx of creatorLut.extendTxs) await sendTx(extendTx, [adminSigner]);
 
// After createMarket, provision a market-specific LUT that excludes creator entries
const marketLut = await client.trade.ensureMarketLookupTable({
  marketId,
  authority: adminKey,
  payer: adminKey,
  creatorLookupTableAddress: creatorLut.lookupTableAddress,
  pageIndexes: [0, 1],
});
if (marketLut.createTx) await sendTx(marketLut.createTx, [adminSigner]);
for (const extendTx of marketLut.extendTxs) await sendTx(extendTx, [adminSigner]);
 
// Before a user claims, add any new proof nodes to the market LUT
await client.trade.extendMarketLookupTable({
  marketId,
  authority: adminKey,
  lookupTableAddress: marketLut.lookupTableAddress,
  creatorLookupTableAddress: creatorLut.lookupTableAddress,
  proofNodes: proof.proof,
});
 
// Build the settle instruction and compile a versioned transaction with both LUTs
const { instruction } = await client.trade.buildSettleInstructionWithProof({
  marketId,
  claimer: userKey,
  assetId,
  pageIndex,
  slotIndex,
  proof,
});
const { message } = await buildV0Message(
  client.program,
  [instruction],
  userKey,
  [creatorLut.lookupTableAddress.toBase58(), marketLut.lookupTableAddress.toBase58()],
);
await sendVtx(message, [userSigner]);

Recursive Market Creation Example

Create a series of daily LIVE markets programmatically.

import DepredictClient, { MarketType, OracleType } from '@endcorp/depredict';
 
async function createDailyMarkets(client: DepredictClient, payer: PublicKey, days = 7) {
  const now = Math.floor(Date.now()/1000);
  for (let i = 0; i < days; i++) {
    const startTime = now + i * 86400; // each day
    const endTime = startTime + 86400; // 24h duration
    const question = `Will SOL close above $200 on day ${i+1}?`;
 
    const { tx, marketId } = await client.trade.createMarket({
      startTime,
      endTime,
      question,
      oracleType: OracleType.MANUAL,
      marketType: MarketType.LIVE,
      metadataUri: 'https://example.com/metadata.json',
      payer,
    });
    // send tx using your wallet adapter / connection
  }
}

You can build any UI/UX you want on top of these primitives—leaderboards, custom market creation flows, trading bots, and more. The SDK is open, composable, and ready for your ideas!

For a full API reference, see the SDK API Reference.

Depredict is an END Corp. project. | Copyright © 2025 END Corp.