DFlow Spot Trading
Swap any pair of Solana tokens via DFlow. Imperative trades (the default) settle synchronously in one transaction; declarative trades are opt-in for users who explicitly want better execution.
Prerequisites
- DFlow docs MCP (
https://pond.dflow.net/mcp) — install per the repo README. This skill is the recipe; the MCP is the reference. Look up endpoint shapes, parameter details, error codes, and anything else field-level viasearch_d_flow/query_docs_filesystem_d_flow— don't guess. dflowCLI (optional, for command-line/agent use) — install per the repo README.
Choose your surface
- CLI — command line, scripts, local agents. Manages keys, signs, broadcasts.
- API — web/mobile apps, backends, automations with their own wallet/signer. Browser apps must proxy HTTP through their backend (the Trading API serves no CORS).
If unclear, ask once: "From the command line, or wired into an app?"
Workflows
Quote (read-only)
- CLI:
dflow quote <atomic-amount> <FROM> <TO> - API:
GET /orderdoubles as a quote — including without auserPublicKey, in which case it returns all price fields with no transaction attached. Use this for live-quote UIs before the user has connected a wallet. Don't reach for/quoteseparately; it's the older surface and the docs redirect back to/order.
Trade — imperative `/order` (the default)
Single round-trip: get a quote and a signed-ready VersionedTransaction together; sign, submit, confirm. Fully synchronous. Works with all SPL + Token-2022 mints.
- CLI:
dflow trade <atomic-amount> <FROM> <TO>(add--confirmfor agents/scripts that need to block until confirmed). - API:
GET /order?userPublicKey=&inputMint=&outputMint=&amount=, deserializetransaction(base64) →VersionedTransaction, sign + broadcast, confirm against the blockhash DFlow signed with. Two broadcast idioms — pick the one that matches your context: - Browser wallet-adapter app (the default for UIs).
const sig = await wallet.sendTransaction(tx, connection). The wallet signs and broadcasts through its own RPC — yourconnectiononly needs to serve reads (confirmTransaction). - Node script / server-side signing with a
Keypair. Two-step:tx.sign([keypair])→connection.sendRawTransaction(tx.serialize()). Your RPC is what broadcasts; a public endpoint will 403.
The full browser-adapter happy path, end to end:
const { transaction, lastValidBlockHeight } = await fetch("/api/order?...").then(r => r.json());
const tx = VersionedTransaction.deserialize(Buffer.from(transaction, "base64"));
const sig = await sendTransaction(tx, connection); // wallet's RPC
await connection.confirmTransaction( // app's RPC (reads only)
{ signature: sig, blockhash: tx.message.recentBlockhash, lastValidBlockHeight },
"confirmed",
);
Where each /order response field goes (don't re-derive these locally — DFlow owns the authoritative value):
transaction(base64) →VersionedTransaction.deserialize→wallet.sendTransaction(browser) orconnection.sendRawTransaction(Node).lastValidBlockHeight→connection.confirmTransaction, paired withtx.message.recentBlockhashfrom the deserialized tx. Never a freshgetLatestBlockhash(see Gotchas).inAmount/outAmount/otherAmountThreshold/priceImpactPct/slippageBps→ display.prioritizationFeeLamports/prioritizationType→ echo / logging. The server-resolved priority-fee choice after"auto"resolution.contextSlot→ logging / staleness checks.routePlan→ optional display / debugging.
Fields marked "Specified if and only if the request included the user's public key" in the OpenAPI (transaction, lastValidBlockHeight, computeUnitLimit, prioritizationFeeLamports, addressLookupTables) are absent on quote-only calls — check before using.