A minimal Next.js 15 app demonstrating HIP-4 prediction markets on Hyperliquid testnet.
- Live recurring prediction markets (BTC, ETH, SOL, HYPE) via WebSocket
- Real-time price feed via
allMidssubscription - Wallet connection (wagmi + injected connector)
- Live orderbook for any market
- Trade form (Buy/Sell Yes/No shares)
- Next.js 15 — App Router, server components by default
- wagmi v2 + viem — wallet connection, no Privy
- Tailwind CSS v4 — utility-first styling
- Zustand — external store pattern with
useSyncExternalStore - Hyperliquid Testnet —
https://api.hyperliquid-testnet.xyz
// src/lib/ws-client.ts
class HyperWsClient { ... }
export const wsClient = new HyperWsClient(); // created once at module level// src/hooks/use-markets.ts
export function useMarkets() {
const state = useSyncExternalStore(
subscribeMarkets,
getMarketSnapshot,
() => ({ markets: [], status: "idle" }) // server snapshot
);
useEffect(() => { initMarkets(); }, []); // lifecycle only
return state;
}const handleSubmit = async (e: FormEvent) => {
e.preventDefault();
// sign + submit order here, in an onClick handler
};bun install
bun run dev # starts on localhost:3003All activity is on Hyperliquid testnet. No real funds involved.
- API:
https://api.hyperliquid-testnet.xyz - WS:
wss://api.hyperliquid-testnet.xyz/ws
- Agent keys: The demo generates a local agent key per wallet session. In production, register it on-chain via
approveAgentfirst. - Order format: Uses legacy asset format
a = 100000000 + coinNumfor prediction market orders. - Tick size: Prices use 5 significant figures (
tick = 10^(floor(log10(price)) - 4)). - Min shares: ~20 shares (depends on current price; ~0.20 USDH minimum).
- Purrdict — the full prediction markets app
- Hyperliquid Docs