BuildTransaction

Cookbook for building, signing, and submitting Flash Trade v2 transactions. Every endpoint returns { "transactionBase64": "…" } (or a quote object containing it). Prerequisite: the wallet is set up and delegated — see SetupIntegration.

Transaction Flow

POST /v2/transaction-builder/{action}

Build the unsigned transaction via the API.

Decode base64

VersionedTransaction.deserialize(Buffer.from(transactionBase64, "base64")).

Sign

Sign with the owner keypair.

Submit to the right RPC

Account & funds ops → Solana RPC. Trades → the v2 RPC.

Confirm

Confirm the signature, then read updated state from the basket snapshot (GET /v2/owner/{owner} or the WebSocket).

Open Position

curl -X POST $FLASH_API_URL/v2/transaction-builder/open-position -H 'Content-Type: application/json' -d '{
  "inputTokenSymbol": "USDC",
  "outputTokenSymbol": "SOL",
  "inputAmountUi": "100.0",
  "leverage": 5.0,
  "tradeType": "LONG",
  "orderType": "MARKET",
  "owner": "<WALLET>",
  "slippagePercentage": "0.5"
}'
  • Limit order: set "orderType": "LIMIT" and "limitPrice": "150.00".

  • Attach TP/SL: add "takeProfit": "160.00" and/or "stopLoss": "130.00".

  • Preview only: omit owner → response has transactionBase64: null.

Close Position

Use the full position USD size for a full close, or a smaller inputUsdUi for a partial close.

Reverse Position

Closes the current LONG and opens a SHORT (or vice versa) atomically. side is the current side.

Add / Remove Collateral

Trigger Orders (TP/SL)

Limit Orders

Funds Movement

See TransactionFlow → Withdraw for the full two-phase sequence.

Signing & Submitting

Error Recovery

  • { "err": "…" } in a 200 body → compute error; fix inputs (symbols, side, amounts) and rebuild.

  • 400 { "error": "…" } from trigger/limit builders → validation error (e.g. bad orderId, TP/SL price vs side).

  • "Blockhash expired" → rebuild and submit immediately.

  • Trade rejected → confirm the basket is delegated and you're submitting to the correct v2 RPC.

  • Withdrawal stuck → call execute-withdrawal to recover.

See ErrorReference for the full matrix.

Last updated

Was this helpful?