Prediction Market API

Initialize new prediction markets on-chain

Prediction Market API

The Prediction Market API provides utilities for initializing new prediction markets on-chain.

Access

const dflow = new DFlowClient();
const predictionMarket = dflow.predictionMarket;

Methods

initializeMarket

Initialize a new prediction market.

import { USDC_MINT } from 'dflow-sdk';
 
const init = await dflow.predictionMarket.initializeMarket({
  marketTicker: 'MY-MARKET-TICKER',
  userPublicKey: wallet.publicKey.toBase58(),
  settlementMint: USDC_MINT, // Optional, defaults to USDC
});
 
console.log(`Transaction: ${init.transaction}`);
console.log(`YES Mint: ${init.yesMint}`);
console.log(`NO Mint: ${init.noMint}`);

Parameters:

NameTypeRequiredDescription
marketTickerstringYesUnique market ticker identifier
userPublicKeystringYesInitializer's wallet public key
settlementMintstringNoSettlement token (default: USDC)

Returns:

interface InitializeMarketResponse {
  transaction: string; // Base64 encoded transaction
  yesMint: string;     // Address of YES outcome token
  noMint: string;      // Address of NO outcome token
}

Market initialization typically requires specific permissions or roles within the DFlow system. Contact DFlow for access to market creation.


Example

Initialize and Execute

import { Connection, Keypair } from '@solana/web3.js';
import { DFlowClient, USDC_MINT, signSendAndConfirm } from 'dflow-sdk';
 
const dflow = new DFlowClient();
const connection = new Connection('https://api.mainnet-beta.solana.com');
const keypair = Keypair.fromSecretKey(/* your key */);
 
// Initialize the market
const init = await dflow.predictionMarket.initializeMarket({
  marketTicker: 'CUSTOM-MARKET-001',
  userPublicKey: keypair.publicKey.toBase58(),
  settlementMint: USDC_MINT,
});
 
console.log('Market initialized:');
console.log(`  YES Token: ${init.yesMint}`);
console.log(`  NO Token: ${init.noMint}`);
 
// Sign and submit the transaction
const result = await signSendAndConfirm(
  connection,
  init.transaction,
  keypair,
  'confirmed'
);
 
console.log(`Transaction confirmed: ${result.signature}`);

Understanding Outcome Tokens

When a prediction market is initialized, two outcome tokens are created:

TokenPurpose
YES TokenRedeemable for 1 unit if the outcome is YES
NO TokenRedeemable for 1 unit if the outcome is NO

These tokens use the Solana TOKEN_2022 program and can be traded like any SPL token.

On this page