Skip to main content
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.
1

Fixed Fees with platformFeeBps

Use platformFeeBps to specify a fixed fee in basis points. Control which token the fee is collected from using platformFeeMode.
const SOL = "So11111111111111111111111111111111111111112";
const USDC = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
const API_BASE_URL = "https://dev-quote-api.dflow.net";

const queryParams = new URLSearchParams();
queryParams.append("inputMint", SOL);
queryParams.append("outputMint", USDC);
queryParams.append("amount", "1000000000");
queryParams.append("platformFeeBps", "50"); // 0.5% fee
queryParams.append("platformFeeMode", "outputMint"); // Collect from output (USDC)
queryParams.append("feeAccount", "YourUSDCTokenAccountAddress");
queryParams.append("userPublicKey", keypair.publicKey.toBase58());

const orderResponse = await fetch(
  `${API_BASE_URL}/order?${queryParams.toString()}`
).then((x) => x.json());
/// To collect fee from input mint instead
queryParams.append("platformFeeMode", "inputMint");
queryParams.append("feeAccount", "YourSOLTokenAccountAddress"); // Must match input mint
/// For /quote endpoint (imperative swaps)
const quoteResponse = await fetch(
  `${API_BASE_URL}/quote?${queryParams.toString()}`
).then((x) => x.json());

/// For /intent endpoint (declarative swaps)
const intentResponse = await fetch(
  `${API_BASE_URL}/intent?${queryParams.toString()}`
).then((x) => x.json());
2

Prediction Market Fees with platformFeeScale

For outcome token trades, use platformFeeScale instead of platformFeeBps. The fee is calculated dynamically based on market probability.
const SOL = "So11111111111111111111111111111111111111112";
const OUTCOME_TOKEN_MINT = "YourOutcomeTokenMint";
const API_BASE_URL = "https://dev-quote-api.dflow.net";

const queryParams = new URLSearchParams();
queryParams.append("inputMint", SOL);
queryParams.append("outputMint", OUTCOME_TOKEN_MINT);
queryParams.append("amount", "1000000000");
queryParams.append("platformFeeScale", "50"); // k = 0.050 in formula k * p * (1 - p) * c
queryParams.append("feeAccount", "YourSettlementMintTokenAccountAddress");
queryParams.append("userPublicKey", keypair.publicKey.toBase58());

const orderResponse = await fetch(
  `${API_BASE_URL}/order?${queryParams.toString()}`
).then((x) => x.json());
For outcome token trades, platformFeeMode is ignored and the fee is always collected in the settlement mint. See the Platform Fees Overview for details on the dynamic fee formula.
3

Fee Account Setup

The feeAccount parameter is required and must match the fee mint. The account must exist before the trade executes.
The fee account must match the token you’re collecting fees in. For outcome token trades, use a settlement mint token account. For other trades, match the input or output mint based on platformFeeMode.
4

Check Fee in Response

Both /order and /quote responses include platformFee information.
const orderResponse = await fetch(
  `${API_BASE_URL}/order?${queryParams.toString()}`
).then((x) => x.json());

if (orderResponse.platformFee) {
  console.log("Platform fee details:", {
    amount: orderResponse.platformFee.amount,
    feeBps: orderResponse.platformFee.feeBps,
    feeAccount: orderResponse.platformFee.feeAccount,
  });
}

Platform Fees Overview

Learn about the theory behind platform fees and the differences between fixed and dynamic fees.

Order Endpoint Reference

Complete API reference for the /order endpoint.

Quote Endpoint Reference

API reference for the /quote endpoint.

Intent Endpoint Reference

API reference for the /intent endpoint.

API Routes

Cookbook Repository

This recipe, along with many more, is available in the DFlow Cookbook Repo. You can clone it and start coding immediately.

Need Help?

https://mintcdn.com/dflow/a8Yx7HBusmKl4Z7w/images/meteor-icons_discord.svg?fit=max&auto=format&n=a8Yx7HBusmKl4Z7w&q=85&s=0ea834bc8a9fa3fe161ba181329effda

Join Our Discord

Connect with other developers, get help, and stay updated on the latest DFlow developments.
https://mintcdn.com/dflow/a8Yx7HBusmKl4Z7w/images/meteor-icons_telegram.svg?fit=max&auto=format&n=a8Yx7HBusmKl4Z7w&q=85&s=e928c5dd68311ff0d419936a35c86eed

Dev Notifications

Join the DFlow Dev Notifications Telegram group to stay in the loop on new features and other announcements.