Sync
Order Sync
After creating, cancelling, or filling a prediction market order on-chain, call this endpoint to sync the order state to the database. This keeps the off-chain order book up to date for API queries and the platform UI.
POST
/api/v1/orders/sync
Syncs an on-chain order event to the database.
Auth: Session or API Key
Request Body (JSON)
Response
{
"txHash": "0x...", // required — transaction hash
"marketType": "public" // optional — "public" (default) or "private"
}What it does
- Fetches the transaction receipt from BSC
- Parses logs for
OrderCreated,OrderCancelled, andOrderFilledevents - Reads current on-chain order state via
marketOrders() - Upserts the order in the database (creates if new, updates if existing)
Response
Response
{ "success": true, "message": "Order synced from transaction." }200 Synced400 Missing or invalid txHash401 Not authenticated422 Sync failed
Example Code
// After creating a sell order on-chain, sync it to the database
const tx = await walletClient.writeContract({
address: PREDICTION_ADDRESS,
abi: PREDICTION_ABI,
functionName: "listOrder",
args: [marketToken, outcomeId, amount, pricePerShare],
});
// Wait for confirmation
await publicClient.waitForTransactionReceipt({ hash: tx });
// Sync to database (works with session cookie or API key)
const syncRes = await fetch("https://launchonbasis.com/api/v1/orders/sync", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-Key": "bsk_your_key",
},
body: JSON.stringify({ txHash: tx, marketType: "public" }),
});
const { success } = await syncRes.json();