React + TypeScript client for a prediction market on Solana: market discovery, wallet connection, on-chain program calls (Anchor), and backend-powered order book depth.
- Wallet UX: Solana Wallet Adapter (modal, multi-wallet) with persistent cluster selection.
- Markets: Browse markets from the API; open a market to see detail, order book, and trade panel.
- On-chain: Anchor
Programwrapper aroundsrc/idl/prediction_market.json— fetch market PDAs, buildplaceOrder/cancelOrdertransactions (align args with your deployed program). - Backend: Typed REST client for markets, order book snapshots, and optional order placement; WebSocket hook scaffold for live book updates.
- Node.js 20+
- A deployed prediction-market program on Solana (update
VITE_PREDICTION_MARKET_PROGRAM_ID). - A backend implementing the API shapes in
src/types/api.ts(or adapt the client).
-
Copy environment file:
cp .env.example .env
-
Fill in RPC URL, program id, and API base URL.
-
Install and run (when you are ready — not run in this repo scaffold by default):
npm install npm run dev
-
Open the URL Vite prints (usually
http://localhost:5173).
| Path | Purpose |
|---|---|
src/config/env.ts |
Reads VITE_* env; cluster + RPC + program id |
src/contexts/SolanaProviders.tsx |
Connection + wallet + modal providers |
src/services/apiClient.ts |
REST integration (markets, orderbook, orders) |
src/services/predictionProgram.ts |
Anchor program, PDA helpers, tx builders |
src/hooks/useOrderbook.ts |
Polling + optional WebSocket merge |
src/components/orderbook/ |
Bid/ask depth UI |
src/components/trading/TradePanel.tsx |
Side, size, price; submits tx + optional API mirror |
src/idl/prediction_market.json |
Replace with IDL from anchor build |
- Export IDL from your Anchor workspace and replace
src/idl/prediction_market.json. - Regenerate or hand-edit instruction names / accounts in
predictionProgram.tsto match the IDL. - Ensure PDA seeds in
deriveMarketPda/deriveOrderPdamatch your Rustseeds!macros.
GET /api/markets
{
"markets": [
{
"address": "J9...marketPDA",
"slug": "fed-cut-2026q2",
"question": "Will the Fed cut rates before Q3 2026?",
"description": "Resolves per committee decision.",
"endTime": "2026-06-30T23:59:59.000Z",
"status": "open",
"volumeUsd": 128400,
"liquidityUsd": 42000,
"yesPrice": 0.42,
"noPrice": 0.58
}
],
"nextCursor": null
}GET /api/markets/:address/orderbook
{
"marketAddress": "J9...",
"bids": [
{ "price": 44, "size": 1200, "outcome": "yes" },
{ "price": 41, "size": 800, "outcome": "no" }
],
"asks": [
{ "price": 46, "size": 500, "outcome": "yes" }
],
"lastUpdated": "2026-03-28T12:00:00.000Z"
}POST /api/orders
{
"marketAddress": "J9...",
"outcome": "yes",
"side": "bid",
"price": 45,
"size": 100,
"clientOrderId": "optional-uuid"
}Response: { "orderId": "ord_...", "status": "accepted" }
- Never commit
.envor private keys. - Validate all off-chain order payloads server-side before signing or matching.
- Prefer your own RPC on mainnet for reliability and rate limits.
npm run dev— Vite dev servernpm run build— Production bundlenpm run preview— Preview production buildnpm run lint— ESLint
- Telegram: https://t.me/DevCutup
- Twitter: https://x.com/devcutup