Smart Contracts SDK
Interact with Cap Bet's Anchor programs on Solana
Smart Contracts SDK
Cap Bet's smart contracts are built with the Anchor framework and deployed on Solana devnet.
Program Information
- Program ID:
13vTbpPE73XtVZ9AxWQMDdasp3M3LXKMMiujqPZvxbkD - Network: Solana Devnet
- Framework: Anchor
- Language: Rust
Installation
npm install @capbet/sdk @coral-xyz/anchor @solana/web3.jsQuick Start
import { AnchorProvider, Program } from '@coral-xyz/anchor';
import { Connection, Keypair } from '@solana/web3.js';
import { CapBet } from '@capbet/sdk';
import idl from '@capbet/sdk/idl.json';
// Setup connection
const connection = new Connection('https://api.devnet.solana.com');
const wallet = Keypair.generate();
const provider = new AnchorProvider(connection, wallet, {});
// Initialize program
const program = new Program(idl, provider);Instructions
Create Market
Create a new betting market:
const marketKeypair = Keypair.generate();
await program.methods
.createMarket(
"Will SOL reach $200?",
new BN(Date.now() / 1000 + 86400 * 30), // Lock time (30 days)
new BN(0.1 * LAMPORTS_PER_SOL), // Min bet
new BN(1000 * LAMPORTS_PER_SOL), // Max bet
)
.accounts({
market: marketKeypair.publicKey,
creator: wallet.publicKey,
systemProgram: SystemProgram.programId,
})
.signers([marketKeypair])
.rpc();Take Opposite Side
Bet on the opposite side of a market:
await program.methods
.takeOpposite(
true, // isYes
new BN(10 * LAMPORTS_PER_SOL), // Amount
)
.accounts({
market: marketPubkey,
position: positionPubkey,
user: wallet.publicKey,
systemProgram: SystemProgram.programId,
})
.rpc();Claim Winnings
Claim winnings after market resolution:
await program.methods
.claim()
.accounts({
market: marketPubkey,
position: positionPubkey,
user: wallet.publicKey,
})
.rpc();State Accounts
Market Account
pub struct Market {
pub creator: Pubkey,
pub title: String,
pub lock_ts: i64,
pub total_yes: u64,
pub total_no: u64,
pub status: MarketStatus,
pub oracle_result: Option<bool>,
}Position Account
pub struct Position {
pub market: Pubkey,
pub user: Pubkey,
pub is_yes: bool,
pub amount: u64,
pub matched_amount: u64,
pub claimed: bool,
}Complete Instruction List
create_market- Create a new betting markettake_opposite- Take opposite side of a betclaim- Claim winningscancel_if_no_opponent- Cancel if no opponentchallenge- Challenge oracle resolutionadjudicate_challenge- Adjudicate challengemanual_resolve- Propose manual resolutionadjudicate_manual_resolution- Validate manual resolutiontimeout_manual_proposal- Timeout manual proposalresolve_pending- Resolve market (oracle)finalize- Finalize after challenge windowwithdraw_unmatched- Withdraw unmatched fundssweep_market- Clean up market data
Error Codes
| Code | Name | Description |
|---|---|---|
| 6000 | MarketLocked | Market is locked for new positions |
| 6001 | MarketNotLocked | Market not yet locked |
| 6002 | AlreadyClaimed | Position already claimed |
| 6003 | NotResolved | Market not yet resolved |
| 6004 | InvalidAmount | Invalid bet amount |
Examples
See complete examples for more detailed use cases.