@gopredix/core
v1.0.0
Published
Core SDK for GoPredix Prediction Markets
Maintainers
Readme
@gopredix/core
Core SDK for GoPredix Prediction Markets
Installation
npm install @gopredix/core
# or
yarn add @gopredix/coreQuick Start
import { GoPredixClient } from '@gopredix/core';
import { ethers } from 'ethers';
// Initialize read-only client
const client = new GoPredixClient({
network: 'testnet',
});
// Fetch markets
const markets = await client.markets.getAllMarkets('BNB');
// For write operations, add a signer
const provider = new ethers.BrowserProvider(window.ethereum);
const signer = await provider.getSigner();
await client.setSigner(signer);
// Create a market
const marketId = await client.markets.createMarket({
question: 'Will BTC reach $100k by end of 2024?',
endTime: Math.floor(Date.now() / 1000) + 86400 * 30,
initialYes: '0.5',
initialNo: '0.5',
}, 'BNB');
// Buy YES tokens
await client.trading.buyYes(marketId, '0.1', 'BNB');API Reference
GoPredixClient
Main SDK client that provides access to all APIs.
Constructor Options:
network: 'testnet' | 'mainnet'provider: Optional custom ethers providersigner: Optional ethers signerapiKey: Optional API key for backend servicesrpcUrl: Optional custom RPC URL
Markets API
getAllMarkets(token, filters?)- Get all marketsgetMarket(id, token)- Get single marketcreateMarket(params, token)- Create new marketvalidateMarket(params)- Validate market with AIgetActiveMarkets(token)- Get only open marketsgetMarketsByCategory(category, token)- Filter by categorygetMarketsCreatedBy(address, token)- Get user's created markets
Trading API
buyYes(marketId, amount, token, minOut?)- Buy YES tokensbuyNo(marketId, amount, token, minOut?)- Buy NO tokenssellYes(marketId, amount, token, minOut?)- Sell YES tokenssellNo(marketId, amount, token, minOut?)- Sell NO tokensgetBuyMultiplier(marketId, amount, isYes, token)- Calculate outputgetUserPositions(address, token)- Get user's positionsclaimWinnings(marketId, token)- Claim resolved market winnings
Accounts API
getUserStats(address, token)- Get user statisticsgetBNBBalance(address)- Get BNB balancegetPDXBalance(address)- Get PDX token balance
Types
All TypeScript types are exported:
import type {
Market,
MarketStatus,
Position,
CreateMarketParams
} from '@gopredix/core';License
MIT
