Skip to main content

Documentation Index

Fetch the complete documentation index at: https://pond.dflow.net/llms.txt

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.
With imperative trades, builders define the exact execution path for a trade, including which venues are used and how the transaction is constructed. Use imperative trades when you need deterministic routing, venue control, or strategy-driven execution. The API aggregates liquidity across major Solana DEXs, so builders can execute trades on any SPL token while retaining full control over how execution happens. To execute an imperative trade, request an order from /order (with userPublicKey), sign it, and submit it to your RPC.
1

Set Up

Imports, constants, and the wallet/connection used across every step.
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 endpoints
const SOL_MINT = "So11111111111111111111111111111111111111112";
const USDC_MINT = process.env.DFLOW_SETTLEMENT_MINT!;
const AMOUNT = 100_000; // 0.0001 SOL (9 decimals)
const SLIPPAGE_BPS = 50; // 0.5%
const DEXES = ["Raydium AMM"]; // single venue for deterministic path

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

Request an order from GET /order using userPublicKey, input/output mints, amount, slippage, and your execution path. The response returns a base64-encoded transaction. Use dexes to enforce a deterministic path (for example, a single venue).
const params = new URLSearchParams({
  inputMint: SOL_MINT,
  outputMint: USDC_MINT,
  amount: AMOUNT.toString(),
  slippageBps: SLIPPAGE_BPS.toString(),
  dexes: DEXES.join(","),
  userPublicKey: keypair.publicKey.toBase58(),
});

const orderResponse = await fetch(`${TRADE_API}/order?${params}`, {
  headers,
}).then((r) => r.json());
3

Sign the Transaction

Deserialize the base64 transaction and sign it with the user’s keypair.
const tx = VersionedTransaction.deserialize(
  Buffer.from(orderResponse.transaction, "base64")
);
tx.sign([keypair]);
4

Submit the Transaction

Submit the signed transaction to a Solana RPC, wait for confirmation, and report success or failure with a link to the transaction on Orb.
const signature = await connection.sendTransaction(tx);
const explorerUrl = `https://orbmarkets.io/tx/${signature}`;

const { value } = await connection.confirmTransaction(signature, "confirmed");

if (value.err) {
  console.log(`Failed: ${JSON.stringify(value.err)}`);
} else {
  console.log("Success: trade landed");
}
console.log(`  Tx: ${explorerUrl}`);

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://mintlify.s3.us-west-1.amazonaws.com/dflow/images/meteor-icons_discord.svg

Join Our Discord

Connect with other developers, get help, and stay updated on the latest DFlow developments.
https://mintlify.s3.us-west-1.amazonaws.com/dflow/images/meteor-icons_telegram.svg

Dev Notifications

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