React SDK
context-markets-react · v0.1.0 · React 18+ · TanStack Query 5+ · wagmi 2+
Declarative React hooks for Context Markets. Built on context-markets and TanStack Query, with automatic wallet integration through wagmi.
Install
Quick start
Provider setup
The
chain prop accepts a ChainOption value (re-exported from context-markets-react) and defaults to "mainnet" (Base). For testnet usage, see the Testnet guide.Using hooks
Hooks
Market hooks
| Hook | Type | Description |
|---|---|---|
useMarkets | Query | List and filter markets |
useMarket | Query | Get a single market by ID |
useOrderbook | Query | Live orderbook for a market |
useQuotes | Query | Current bid/ask/last prices |
usePriceHistory | Query | Historical price data |
useMarketActivity | Query | Market event feed |
useSimulateTrade | Query | Preview trade execution |
useOracle | Query | Oracle resolution data |
useSearchMarkets | Query | Search markets by keyword |
useLatestOracleQuote | Query | Latest oracle quote for a market |
Market creation hooks
| Hook | Type | Description |
|---|---|---|
useAgentSubmit | Mutation | Submit a market draft via agent endpoint |
useAgentSubmitAndWait | Mutation | Submit and poll until market is created |
Order hooks
| Hook | Type | Description |
|---|---|---|
useOrders | Query | List orders with filters |
useMyOrders | Query | Your open orders |
useCreateOrder | Mutation | Place a limit order |
useMarketOrder | Mutation | Place a market order |
useCancelOrder | Mutation | Cancel an order |
useCancelReplaceOrder | Mutation | Cancel and replace an order |
Portfolio hooks
| Hook | Type | Description |
|---|---|---|
usePositions | Query | View positions across markets |
useBalance | Query | USDC balance (wallet + settlement) |
useClaimable | Query | Winnings from resolved markets |
usePortfolioStats | Query | Portfolio value and PnL |
Account hooks
| Hook | Type | Description |
|---|---|---|
useAccountStatus | Query | Account approvals and balances |
useAccountSetup | Mutation | Approve contracts (chain-aware) |
useDeposit | Mutation | Deposit USDC (chain-aware) |
useWithdraw | Mutation | Withdraw USDC |
useApproveUsdc | Mutation | Approve USDC spending |
useApproveOperator | Mutation | Approve operator |
Query keys
UsecontextKeys for manual cache invalidation:
Best practices
Query patterns, cache invalidation, wallet connection
Hooks reference
Complete hook signatures and parameters