> ## 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.

# Send Orders

> Send a spot order with the DFlow Trading API: request, sign, and submit

<Info>
  During development, you can use the [developer endpoints](/get-started/endpoints) without an API key. For production use, [request an API key](/get-started/api-key) for higher rate limits.
</Info>

This recipe sends a SOL → USDC order on DFlow: request an order, sign the returned transaction, and submit it through your RPC.

```mermaid theme={null}
flowchart LR
  A[Request /order] --> B[Sign transaction]
  B --> C[Submit to RPC]
```

<Tabs>
  <Tab title="Transaction v1">
    <Note>
      Classic `@solana/web3.js` can't sign or send v1 transactions (it can only
      read them back). This flow uses `@solana/kit` 8.0.0+ instead, which has
      a different API shape than the rest of this site's recipes.
    </Note>

    <Steps>
      <Step title="Set up">
        Imports, env config, and the wallet/RPC client used across every step.

        <AccordionGroup>
          <Accordion title="Imports, env, and wallet">
            ```typescript theme={null}
            import "dotenv/config";

            import {
              createKeyPairFromBytes,
              createSolanaRpc,
              getAddressFromPublicKey,
              getBase64Encoder,
              getBase64EncodedWireTransaction,
              getTransactionDecoder,
              signTransaction,
            } from "@solana/kit";
            import bs58 from "bs58";

            const DFLOW_TRADE_API_URL = process.env.DFLOW_TRADE_API_URL ?? "https://dev-quote-api.dflow.net";
            const DFLOW_API_KEY = process.env.DFLOW_API_KEY; // optional; not needed for dev endpoints
            const DFLOW_SETTLEMENT_MINT = process.env.DFLOW_SETTLEMENT_MINT ?? "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"; // USDC
            const SOLANA_RPC_URL = process.env.SOLANA_RPC_URL ?? "https://api.mainnet-beta.solana.com";

            const SOL_MINT = "So11111111111111111111111111111111111111112";
            const AMOUNT = 10_000_000; // 0.01 SOL (9 decimals)
            const SLIPPAGE_BPS = 50; // 0.5%

            const rpc = createSolanaRpc(SOLANA_RPC_URL);
            const keyPair = await createKeyPairFromBytes(
              bs58.decode(process.env.SOLANA_PRIVATE_KEY ?? "")
            );
            const walletAddress = await getAddressFromPublicKey(keyPair.publicKey);

            const headers: HeadersInit = {};
            if (DFLOW_API_KEY) headers["x-api-key"] = DFLOW_API_KEY;
            ```
          </Accordion>
        </AccordionGroup>
      </Step>

      <Step title="Request an order">
        [`GET /order`](/resources/trading-api/order/order) returns a quote and a base64-encoded transaction in one call. Pass `userPublicKey` so DFlow can construct the transaction for you to sign, and `transactionVersion` to opt into v1.

        <AccordionGroup>
          <Accordion title="Request an order">
            ```typescript theme={null}
            const params = new URLSearchParams({
              inputMint: SOL_MINT,
              outputMint: DFLOW_SETTLEMENT_MINT,
              amount: AMOUNT.toString(),
              slippageBps: SLIPPAGE_BPS.toString(),
              userPublicKey: walletAddress,
              transactionVersion: "v1",
            });

            const orderResponse = await fetch(
              `${DFLOW_TRADE_API_URL}/order?${params}`,
              { headers }
            ).then((r) => r.json());
            ```
          </Accordion>
        </AccordionGroup>
      </Step>

      <Step title="Sign and submit">
        Decode the returned wire transaction, sign it with the user's keypair, and submit it through your RPC.

        <AccordionGroup>
          <Accordion title="Sign and submit">
            ```typescript theme={null}
            const transactionBytes = getBase64Encoder().encode(orderResponse.transaction);
            const transaction = getTransactionDecoder().decode(transactionBytes);
            const signedTransaction = await signTransaction([keyPair], transaction);

            const wireTransaction = getBase64EncodedWireTransaction(signedTransaction);
            const signature = await rpc
              .sendTransaction(wireTransaction, { encoding: "base64" })
              .send();
            const explorerUrl = `https://orbmarkets.io/tx/${signature}`;

            // Simplified: polling for confirmation is omitted here. Add a
            // getSignatureStatuses poll (or your framework's confirm helper) before
            // treating the trade as landed.
            console.log("Submitted:", signature);
            console.log(`  Tx: ${explorerUrl}`);
            ```
          </Accordion>
        </AccordionGroup>
      </Step>
    </Steps>
  </Tab>

  <Tab title="Transaction v0">
    <Steps>
      <Step title="Set up">
        Imports, env config, and the wallet/connection used across every step.

        <AccordionGroup>
          <Accordion title="Imports, env, and wallet">
            ```typescript theme={null}
            import "dotenv/config";

            import {
              Connection,
              Keypair,
              VersionedTransaction,
            } from "@solana/web3.js";
            import bs58 from "bs58";

            const DFLOW_TRADE_API_URL = process.env.DFLOW_TRADE_API_URL ?? "https://dev-quote-api.dflow.net";
            const DFLOW_API_KEY = process.env.DFLOW_API_KEY; // optional; not needed for dev endpoints
            const DFLOW_SETTLEMENT_MINT = process.env.DFLOW_SETTLEMENT_MINT ?? "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"; // USDC
            const SOLANA_RPC_URL = process.env.SOLANA_RPC_URL ?? "https://api.mainnet-beta.solana.com";

            const SOL_MINT = "So11111111111111111111111111111111111111112";
            const AMOUNT = 10_000_000; // 0.01 SOL (9 decimals)
            const SLIPPAGE_BPS = 50; // 0.5%

            const connection = new Connection(SOLANA_RPC_URL, "confirmed");
            const keypair = Keypair.fromSecretKey(
              bs58.decode(process.env.SOLANA_PRIVATE_KEY ?? "")
            );

            const headers: HeadersInit = {};
            if (DFLOW_API_KEY) headers["x-api-key"] = DFLOW_API_KEY;
            ```
          </Accordion>
        </AccordionGroup>
      </Step>

      <Step title="Request an order">
        [`GET /order`](/resources/trading-api/order/order) returns a quote and a base64-encoded transaction in one call. Pass `userPublicKey` so DFlow can construct the transaction for you to sign.

        <AccordionGroup>
          <Accordion title="Request an order">
            ```typescript theme={null}
            const params = new URLSearchParams({
              inputMint: SOL_MINT,
              outputMint: DFLOW_SETTLEMENT_MINT,
              amount: AMOUNT.toString(),
              slippageBps: SLIPPAGE_BPS.toString(),
              userPublicKey: keypair.publicKey.toBase58(),
            });

            const orderResponse = await fetch(
              `${DFLOW_TRADE_API_URL}/order?${params}`,
              { headers }
            ).then((r) => r.json());
            ```
          </Accordion>
        </AccordionGroup>
      </Step>

      <Step title="Sign and submit">
        Deserialize the returned transaction, sign it with the user's keypair, and submit it through your RPC.

        <AccordionGroup>
          <Accordion title="Sign and submit">
            ```typescript theme={null}
            const tx = VersionedTransaction.deserialize(
              Buffer.from(orderResponse.transaction, "base64")
            );
            tx.sign([keypair]);

            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}`);
            ```
          </Accordion>
        </AccordionGroup>
      </Step>
    </Steps>
  </Tab>
</Tabs>

## Related Resources

<CardGroup cols={2}>
  <Card title="Spot Trading" href="/spot/introduction" icon="arrow-right-arrow-left">
    How spot trading works on DFlow.
  </Card>

  <Card title="Add Platform Fees" href="/spot/recipes/platform-fees" icon="percent">
    Monetize trades with builder fees.
  </Card>

  <Card title="Add Priority Fees" href="/spot/recipes/priority-fees" icon="bolt">
    Control execution speed with priority fees.
  </Card>

  <Card title="Authenticate Requests" href="/resources/recipes/api-keys" icon="key">
    Authenticate requests for production rate limits.
  </Card>
</CardGroup>

## API Routes

* [`GET /order`](/resources/trading-api/order/order)
