Skip to main content
All query hooks are built on TanStack Query v5. They return { data, isLoading, isError, error } and handle caching, deduplication, and background refetching automatically.

useGlobalState

Fetches the protocol config: fee rates and accepted USDC mint.
TypeScript
Always read globalState.acceptedMint at runtime. Don’t hardcode the USDC mint address - it differs between devnet and mainnet.
Cache TTL: 30 seconds.

useMarkets

Fetches markets. Filter by creator, state, or a known list of IDs.
TypeScript
Each item in the array is { publicKey: PublicKey, account: MarketAccount }.
The { ids } filter mode was added in v0.8.8. It’s the recommended path once a deployment has more than a few hundred markets — useMarkets() with no filter still calls getProgramAccounts and returns the full payload.
Memoize the filter object when it’s derived in render (e.g. from query results) so TanStack Query sees a stable input:
TypeScript
Cache TTL: 10 seconds. Pass refetchInterval: 4000 for live odds updates.

useMarketQuestions

Batch-fetches the question text for a list of markets (typically the output of useMarkets). Routes through the SDK’s RPC batching layer, so it scales past Solana’s 100-key getMultipleAccountsInfo cap.
TypeScript
Returns Map<marketPdaBase58, questionString>. Markets without a MarketQuestion PDA (legacy v1/v2 inline-question markets) are omitted from the map - fall back to account.inlineQuestion for those.
Stabilize the input array so TanStack Query keys don’t churn every render:
TypeScript
Cache TTL: 60 seconds. Questions are immutable after market creation. Query is automatically disabled when the markets list is empty. Available since v0.8.8.

useMarket

Fetches a single market by ID.
TypeScript
Use the enabled option to gate on prerequisites:
TypeScript
Cache TTL: 10 seconds.

useUserPositions

Fetches all positions (bets) for a wallet across all markets.
TypeScript
Cache TTL: 5 seconds.

usePosition

Fetches a single position by market, user, and bet index.
TypeScript
Cache TTL: 5 seconds.

Cache TTL reference


Manual cache invalidation

If you send raw instructions outside of mutation hooks, invalidate the cache yourself using the query key factories:
TypeScript