Back to Docs
API Reference
AnimeMarkets
The main client class for interacting with Prediction Anime Markets on Solana.
Constructor
import { AnimeMarkets, AnimeMarketsOptions } from '@anime-markets/sdk';
import { Connection, PublicKey } from '@solana/web3.js';
const client = new AnimeMarkets(options: AnimeMarketsOptions);
interface AnimeMarketsOptions {
// Required: Solana connection
connection: Connection;
// Required: Wallet adapter (Phantom, Solflare, etc.)
wallet: {
publicKey: PublicKey;
signTransaction: (tx: Transaction) => Promise<Transaction>;
signAllTransactions: (txs: Transaction[]) => Promise<Transaction[]>;
};
// Required: Network to connect to
network: 'mainnet-beta' | 'devnet';
// Optional: API key for higher rate limits
apiKey?: string;
// Optional: Program ID (defaults to official deployment)
programId?: PublicKey;
// Optional: Enable debug logging
debug?: boolean;
}getMarkets(options?)
Fetches all available prediction markets with optional filtering.
Example
import { MarketStatus, SortBy, SortOrder } from '@anime-markets/sdk';
import { LAMPORTS_PER_SOL } from '@solana/web3.js';
// Get all markets
const allMarkets = await client.getMarkets();
// Get filtered markets
const filteredMarkets = await client.getMarkets({
status: MarketStatus.ACTIVE,
category: 'One Piece',
sortBy: SortBy.VOLUME,
sortOrder: SortOrder.DESC,
limit: 10,
offset: 0,
});
// Filter options interface
interface GetMarketsOptions {
status?: MarketStatus; // PENDING, ACTIVE, PAUSED, RESOLVED, CANCELLED
category?: AnimeCategory; // Filter by anime
sortBy?: SortBy; // CREATED_AT, ENDS_AT, VOLUME, PARTICIPANTS
sortOrder?: SortOrder; // ASC, DESC
limit?: number; // Max results (default: 50)
offset?: number; // Pagination offset
search?: string; // Search in title/description
}
// Returns: Market[]
interface Market {
id: string;
publicKey: PublicKey; // Solana account address
title: string;
description: string;
category: AnimeCategory;
imageUrl: string;
yesPercentage: number;
noPercentage: number;
yesPool: number; // In lamports
noPool: number; // In lamports
totalVolume: number; // In lamports
participants: number;
createdAt: Date;
endsAt: Date;
resolvedAt?: Date;
status: MarketStatus;
outcome?: BetOutcome;
}
// Display volume in SOL
console.log('Volume:', market.totalVolume / LAMPORTS_PER_SOL, 'SOL');placeBet(options)
Places a bet on a specific market outcome. Returns a transaction signature.
Example
import { BetOutcome } from '@anime-markets/sdk';
import { LAMPORTS_PER_SOL } from '@solana/web3.js';
// Place a bet
const signature = await client.placeBet({
marketId: 'gojo-returns-2025',
amount: 0.5 * LAMPORTS_PER_SOL, // 0.5 SOL
outcome: BetOutcome.YES,
slippage: 0.01, // Optional: 1% slippage tolerance
});
// Wait for confirmation
const confirmation = await client.connection.confirmTransaction(signature, 'confirmed');
if (confirmation.value.err) {
throw new Error('Transaction failed');
}
console.log('Bet placed! Signature:', signature);
console.log('View on Solscan:', `https://solscan.io/tx/${signature}`);
// PlaceBetOptions interface
interface PlaceBetOptions {
marketId: string; // Market to bet on
amount: number; // Bet amount in lamports
outcome: BetOutcome; // YES or NO
slippage?: number; // Slippage tolerance (0.01 = 1%)
referrer?: PublicKey; // Optional referrer address
}estimatePayout(options)
Estimates the potential payout for a bet without executing it.
Example
import { LAMPORTS_PER_SOL } from '@solana/web3.js';
const estimate = await client.estimatePayout({
marketId: 'frieren-aoty-2025',
amount: 1 * LAMPORTS_PER_SOL, // 1 SOL
outcome: BetOutcome.YES,
});
console.log('Bet amount:', estimate.amount / LAMPORTS_PER_SOL, 'SOL');
console.log('Shares received:', estimate.shares);
console.log('Potential payout:', estimate.payout / LAMPORTS_PER_SOL, 'SOL');
console.log('Implied odds:', estimate.impliedOdds, '%');
console.log('Price impact:', estimate.priceImpact, '%');
// EstimatePayoutResult interface
interface EstimatePayoutResult {
amount: number; // Input amount in lamports
shares: number; // Shares to receive
payout: number; // Potential payout in lamports if win
impliedOdds: number; // Current implied probability
priceImpact: number; // Price impact of this bet
}getUserBets(publicKey, options?)
Fetches all bets placed by a specific wallet.
Example
import { LAMPORTS_PER_SOL, PublicKey } from '@solana/web3.js';
const userPublicKey = client.wallet.publicKey;
// Get all bets
const allBets = await client.getUserBets(userPublicKey);
// Get filtered bets
const activeBets = await client.getUserBets(userPublicKey, {
marketStatus: MarketStatus.ACTIVE,
claimed: false,
});
// Calculate total invested
const totalInvested = activeBets.reduce(
(sum, bet) => sum + bet.amount,
0
);
console.log('Active bets:', activeBets.length);
console.log('Total invested:', totalInvested / LAMPORTS_PER_SOL, 'SOL');
// Bet interface
interface Bet {
id: string;
marketId: string;
user: PublicKey;
amount: number; // In lamports
outcome: BetOutcome;
shares: number;
timestamp: Date;
signature: string; // Solana transaction signature
claimed: boolean;
payout?: number; // In lamports
}subscribe(event, callback)
Subscribe to real-time events via Solana WebSocket.
Example
import { EventType } from '@anime-markets/sdk';
import { LAMPORTS_PER_SOL } from '@solana/web3.js';
// Subscribe to new bets
const subscriptionId = client.subscribe(EventType.BET_PLACED, (event) => {
console.log('New bet!');
console.log(' Market:', event.marketId);
console.log(' User:', event.user.toString());
console.log(' Amount:', event.amount / LAMPORTS_PER_SOL, 'SOL');
console.log(' Outcome:', event.outcome);
});
// Subscribe to market resolutions
client.subscribe(EventType.MARKET_RESOLVED, (event) => {
console.log(`Market ${event.marketId} resolved: ${event.outcome}`);
});
// Subscribe to specific market account changes
const marketPublicKey = new PublicKey('...');
client.subscribeToMarket(marketPublicKey, (update) => {
console.log('Market updated!');
console.log(' YES:', update.yesPercentage, '%');
console.log(' NO:', update.noPercentage, '%');
console.log(' Volume:', update.totalVolume / LAMPORTS_PER_SOL, 'SOL');
});
// Cleanup
await client.connection.removeAccountChangeListener(subscriptionId);