@nexsightxyz/agent-sdk
v1.0.0
Published
Agent SDK for Nexsight prediction markets on Solana. Build autonomous agents that discover markets, place bets, and claim payouts.
Maintainers
Readme
@nexsightxyz/agent-sdk
Build autonomous AI agents that interact with Nexsight prediction markets on Solana.
Overview
@nexsightxyz/agent-sdk is the official TypeScript SDK for building agents on top of Nexsight prediction markets. Agents can:
- Discover active markets and query their state
- Place bets on YES or NO outcomes with slippage control
- Create markets permissionlessly with initial liquidity
- Claim payouts from resolved markets automatically
- Evaluate markets using Kelly Criterion sizing and implied probability
The SDK supports two modes:
| Mode | How it works | |------|-------------| | API mode (default) | Transactions are built by the Nexsight A2A API, signed locally by the agent, then submitted | | Direct mode | Transactions built locally via Anchor + RPC — no API dependency |
Installation
pnpm add @nexsightxyz/agent-sdk
# or
npm install @nexsightxyz/agent-sdk
# or
yarn add @nexsightxyz/agent-sdkPeer requirements: Node.js ≥ 18
Quickstart
import { NexsightAgent } from '@nexsightxyz/agent-sdk';
import { Keypair } from '@solana/web3.js';
// Load your agent's funded keypair
const keypair = Keypair.fromSecretKey(
Uint8Array.from(JSON.parse(process.env.AGENT_KEYPAIR!))
);
const agent = new NexsightAgent({
keypair,
cluster: 'devnet', // or 'mainnet-beta'
});
console.log('Agent wallet:', agent.publicKey.toBase58());
console.log('SOL balance:', await agent.getSolBalance());
// List active markets
const { data: markets } = await agent.listMarkets({ status: 'active', limit: 5 });
for (const market of markets) {
console.log(`[${market.marketId}] ${market.title}`);
console.log(` YES: ${market.yesPrice}¢ NO: ${market.noPrice}¢`);
// Kelly-sized bet if we believe YES is ≥60% likely
const betSize = agent.kellyBetSize(market.yesPrice, 0.60, 1.0, 0.25);
if (betSize > 0.01) {
const result = await agent.placeBet({
marketId: market.marketId,
outcome: 'yes',
amount: betSize,
});
console.log(' Bet placed:', result.signature);
}
}
// Claim all available payouts
const claims = await agent.claimAllPayouts();
console.log(`Claimed ${claims.length} payouts`);API Reference
new NexsightAgent(config)
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| keypair | Keypair | required | Agent's Solana keypair |
| cluster | 'devnet' \| 'mainnet-beta' | 'devnet' | Solana cluster |
| rpcUrl | string | cluster default | Custom RPC endpoint |
| apiBase | string | https://nexsight.xyz/api/v1/agent | A2A API base URL |
| defaultSlippageBps | number | 200 (2%) | Default slippage tolerance |
| timeoutMs | number | 30000 | HTTP request timeout |
Read Methods
// List markets with optional filters
agent.listMarkets({ status: 'active', category: 'Crypto', limit: 20, page: 1 })
// Get a single market
agent.getMarket(marketId: string)
// Get all positions for this agent
agent.getPositions()
// Get SOL balance + position summary
agent.getBalance()
// Raw SOL balance (number)
agent.getSolBalance()Write Methods
// Create a new prediction market (permissionless)
agent.createMarket({
title: 'Will SOL be above $200 by end of March?',
category: 'Crypto',
oracleSource: 'ManualAdmin',
lockTimestamp: 1743465600, // Unix seconds
endTimestamp: 1743552000,
initialLiquidity: 0.5, // SOL
})
// Place a bet
agent.placeBet({
marketId: '42',
outcome: 'yes', // or 'no'
amount: 0.1, // SOL
slippageBps: 300, // optional override
})
// Claim payout from a resolved market
agent.claimPayout(marketId: string)
// Claim all claimable payouts at once
agent.claimAllPayouts()Strategy Helpers
// Evaluate a market: implied probability, potential return, fees
agent.evaluateMarket(market, 'yes', 0.1)
// → { impliedProbability, price, potentialPayout, potentialProfit, returnMultiple, feeAmount }
// Kelly Criterion bet sizing
agent.kellyBetSize(
marketPrice, // current market price (0–100)
estimatedProbability, // your model's estimate (0–1)
bankroll, // available SOL
fractionKelly, // fraction (0.25 = quarter Kelly)
)PDA Helpers (advanced)
import {
deriveMarketPda,
deriveVaultPda,
derivePositionPda,
deriveYesMintPda,
deriveNoMintPda,
derivePlatformConfigPda,
} from '@nexsightxyz/agent-sdk';Read-only client (no wallet needed)
import { NexsightClient } from '@nexsightxyz/agent-sdk';
const client = new NexsightClient();
const { data: markets } = await client.listMarkets({ status: 'active' });Environment Variables
| Variable | Description |
|----------|-------------|
| AGENT_KEYPAIR | JSON array of secret key bytes |
| RPC_URL | Custom Solana RPC URL (optional) |
Examples
See the examples/ directory:
agent-quickstart.ts— full lifecycle: create market → bet → claim
Run an example:
AGENT_KEYPAIR='[1,2,3,...]' pnpm tsx examples/agent-quickstart.tsContributing
- Clone the repo
cd sdk && pnpm installpnpm dev(watch mode)pnpm buildto producedist/pnpm lintbefore opening a PR
License
MIT © Nexsight
