Documentation
Everything you need to build with Prediction Anime Markets
Quick Start
Install SDK
npm install @anime-markets/sdk ethers@6Initialize & Connect
import { AnimeMarkets } from '@anime-markets/sdk';
import { ethers } from 'ethers';
// Connect to user's wallet
const provider = new ethers.BrowserProvider(window.ethereum);
const signer = await provider.getSigner();
// Initialize the SDK
const client = new AnimeMarkets({
signer,
network: 'mainnet',
});
// Fetch all active markets
const markets = await client.getMarkets({ status: 'ACTIVE' });
console.log(`Found ${markets.length} active markets`);Code Examples
Place a Bet on a Market
import { AnimeMarkets, BetOutcome } from '@anime-markets/sdk';
import { parseEther } from 'ethers';
async function placeBet(client: AnimeMarkets) {
// Get market details first
const market = await client.getMarket('luffy-vs-blackbeard');
if (market.status !== 'ACTIVE') {
throw new Error('Market is not active for betting');
}
// Place a YES bet for 0.5 ETH
const tx = await client.placeBet({
marketId: market.id,
amount: parseEther('0.5'),
outcome: BetOutcome.YES,
slippage: 0.01, // 1% slippage tolerance
});
console.log('Transaction submitted:', tx.hash);
// Wait for confirmation
const receipt = await tx.wait();
console.log('Bet confirmed in block:', receipt.blockNumber);
// Get updated odds
const updatedMarket = await client.getMarket(market.id);
console.log('New YES odds:', updatedMarket.yesPercentage + '%');
}React Hook for Markets
import { useAnimeMarkets, useMarkets } from '@anime-markets/react';
import { useAccount, useConnect } from 'wagmi';
function MarketsList() {
const { address, isConnected } = useAccount();
const { connect, connectors } = useConnect();
// Initialize SDK with connected wallet
const client = useAnimeMarkets({
network: 'mainnet',
});
// Fetch markets with SWR caching
const { data: markets, isLoading, error } = useMarkets(client, {
category: 'One Piece',
status: 'ACTIVE',
refreshInterval: 30000, // Refresh every 30s
});
if (!isConnected) {
return (
<button onClick={() => connect({ connector: connectors[0] })}>
Connect Wallet
</button>
);
}
if (isLoading) return <div>Loading markets...</div>;
if (error) return <div>Error: {error.message}</div>;
return (
<div>
{markets?.map((market) => (
<div key={market.id}>
<h3>{market.title}</h3>
<p>YES: {market.yesPercentage}%</p>
<p>Volume: {market.totalVolume} ETH</p>
</div>
))}
</div>
);
}Subscribe to Real-time Events
import { AnimeMarkets, EventType } from '@anime-markets/sdk';
async function subscribeToEvents(client: AnimeMarkets) {
// Subscribe to all bet events
const unsubscribeBets = client.subscribe(EventType.BET_PLACED, (event) => {
console.log(`New bet on ${event.marketId}`);
console.log(` User: ${event.user}`);
console.log(` Amount: ${event.amount} ETH`);
console.log(` Outcome: ${event.outcome}`);
});
// Subscribe to market resolutions
const unsubscribeResolutions = client.subscribe(
EventType.MARKET_RESOLVED,
(event) => {
console.log(`Market resolved: ${event.marketId}`);
console.log(` Outcome: ${event.outcome ? 'YES' : 'NO'}`);
console.log(` Total pool: ${event.totalPool} ETH`);
}
);
// Subscribe to specific market
const unsubscribeMarket = client.subscribeToMarket(
'gojo-returns-2025',
(event) => {
console.log('Market update:', event);
}
);
// Cleanup when done
return () => {
unsubscribeBets();
unsubscribeResolutions();
unsubscribeMarket();
};
}TypeScript Types
// Core Types
interface Market {
id: string;
title: string;
description: string;
category: AnimeCategory;
imageUrl: string;
yesPercentage: number;
noPercentage: number;
yesPool: bigint;
noPool: bigint;
totalVolume: bigint;
participants: number;
createdAt: Date;
endsAt: Date;
resolvedAt?: Date;
status: MarketStatus;
outcome?: BetOutcome;
}
type MarketStatus = 'PENDING' | 'ACTIVE' | 'PAUSED' | 'RESOLVED' | 'CANCELLED';
type BetOutcome = 'YES' | 'NO';
type AnimeCategory =
| 'One Piece'
| 'Jujutsu Kaisen'
| 'Demon Slayer'
| 'Chainsaw Man'
| 'Frieren'
| 'Solo Leveling'
| 'Attack on Titan'
| 'My Hero Academia'
| 'Other';
interface Bet {
id: string;
marketId: string;
user: string;
amount: bigint;
outcome: BetOutcome;
shares: bigint;
timestamp: Date;
transactionHash: string;
claimed: boolean;
payout?: bigint;
}
interface PlaceBetOptions {
marketId: string;
amount: bigint;
outcome: BetOutcome;
slippage?: number;
deadline?: number;
}SDK Features
Type-Safe
Full TypeScript support with complete type definitions for all methods and responses.
React Hooks
Built-in React hooks with SWR for efficient data fetching and caching.
Real-time
WebSocket subscriptions for live market updates and bet notifications.
Gas Optimized
Automatic gas estimation and optimization for all transactions.