Use this file to discover all available pages before exploring further.
During development, you can use the developer endpoints without an API key. For production use, you’ll need an API key to avoid rate limits.
This recipe swaps USDC for a single prediction-market outcome token (YES or NO) through the standard /order endpoint. Prediction-market trades on DFlow are always asynchronous: the user signs and submits one open transaction, the server fills the order across one or more follow-on transactions, and the app polls /order-status until the order reaches a terminal state.
This recipe assumes familiarity with Solana’s transaction and network connection logic. If unfamiliar, see the Solana Cookbook.
1
Set Up
Imports, constants, and the wallet/connection used across every step. Replace OUTCOME_TOKEN_MINT with a real YES or NO mint; use the Discover Markets recipe to find one.
Imports, Constants, and Wallet
import "dotenv/config";import { Connection, Keypair, VersionedTransaction,} from "@solana/web3.js";import bs58 from "bs58";const TRADE_API = process.env.DFLOW_TRADE_API_URL!;const API_KEY = process.env.DFLOW_API_KEY; // Not needed with dev endpointsconst USDC_MINT = process.env.DFLOW_SETTLEMENT_MINT!;const OUTCOME_TOKEN_MINT = "REPLACE_ME"; // YES or NO mint from /build/recipes/prediction-markets/discover-marketsconst BUY_AMOUNT = 1_000_000; // $1 USDC (6 decimals)const SLIPPAGE_BPS = 50; // 0.5%const connection = new Connection(process.env.SOLANA_RPC_URL!, "confirmed");const keypair = Keypair.fromSecretKey( bs58.decode(process.env.SOLANA_PRIVATE_KEY!));const headers: HeadersInit = {};if (API_KEY) headers["x-api-key"] = API_KEY;
2
Request an Order
GET /order returns a quote and an unsigned base64 transaction in one call.
Deserialize the returned transaction, sign with the keypair, and submit it. This is the open transaction; the server will fill the order across follow-on transactions tracked by signature.