Install PredictKit via npm or yarn:
npm install @predictkit/react @predictkit/sdk wagmi viemPredictKit requires wagmi and viem as peer dependencies for wallet connection and blockchain interaction.
Build your first prediction market in less than 10 minutes. This guide will walk you through installation, setup, and creating your first market.
Install PredictKit via npm or yarn:
npm install @predictkit/react @predictkit/sdk wagmi viemPredictKit requires wagmi and viem as peer dependencies for wallet connection and blockchain interaction.
PredictKit integrates with wagmi for wallet connections. First, set up your providers:
// providers.tsx
import { WagmiProvider, usePublicClient, useWalletClient, useAccount } from 'wagmi';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { PredictKitProvider } from '@predictkit/react';
import { config } from './wagmi';
// Wrapper to access wagmi hooks
function PredictKitWrapper({ children }) {
const publicClient = usePublicClient();
const { data: walletClient } = useWalletClient();
const { address } = useAccount();
return (
<PredictKitProvider
factoryAddress="0x..."
publicClient={publicClient}
walletClient={walletClient}
userAddress={address}
rpcUrl="https://bsc-testnet.publicnode.com"
>
{children}
</PredictKitProvider>
);
}
export function Providers({ children }) {
const [queryClient] = useState(() => new QueryClient());
return (
<WagmiProvider config={config}>
<QueryClientProvider client={queryClient}>
<PredictKitWrapper>
{children}
</PredictKitWrapper>
</QueryClientProvider>
</WagmiProvider>
);
}The wrapper pattern allows PredictKitProvider to access wagmi hooks for wallet state.
Use the MarketList component to show all available markets:
import { MarketList } from '@predictkit/react';
function MarketsPage() {
return (
<MarketList
filter="active" // 'all' | 'active' | 'resolved'
sortBy="tvl" // 'tvl' | 'recent' | 'ending-soon'
onMarketClick={(market) => {
console.log('Market:', market.address);
}}
/>
);
}Use the PredictionWidget component for a complete betting interface:
import { PredictionWidget } from '@predictkit/react';
function MarketDetailPage({ marketAddress }) {
return (
<PredictionWidget
marketAddress={marketAddress}
onBetPlaced={(txHash) => {
console.log('Bet placed!', txHash);
}}
onError={(error) => {
console.error('Error:', error);
}}
/>
);
}The widget includes odds display, bet amount input, and transaction handling.
Now that you've set up PredictKit, here are some recommended next steps: