SDK Class
Complete reference for the SDK class methods.
Overview
The SDK class is the main entry point for interacting with the Poll.fun betting protocol.
Initialization
SDK.build()
Creates a new SDK instance.
import { SDK } from "@solworks/poll-sdk";
import { Connection } from "@solana/web3.js";
const sdk = SDK.build({
connection: new Connection("https://api.devnet.solana.com"),
wallet: walletAdapter,
skipPreflight: false,
commitment: "confirmed",
maxRetries: 5,
});Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
connection | Connection | Yes | Solana RPC connection |
wallet | IWallet | No | Wallet adapter for signing |
skipPreflight | boolean | No | Skip preflight transaction checks |
commitment | Commitment | No | Transaction confirmation level |
maxRetries | number | No | Max transaction retry attempts |
User Methods
createUser()
Creates an onchain program user account.
const txHash = await sdk.createUser({
signers: [wallet],
});Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
signers | Keypair[] | Yes | Transaction signers |
payerOverride | PublicKey | No | Override fee payer |
confirmOptions | ConfirmOptions | No | Confirmation options |
Returns: Promise<string> - Transaction signature
Bet Methods (V2)
initializeBetV2()
Creates a new bet (prediction market).
const txHash = await sdk.initializeBetV2({
question: "Will Bitcoin hit $100k?",
expectedUserCount: 10,
minimumVoteCount: 2,
isCreatorResolver: false,
signers: [wallet],
});Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
question | string | Yes | Bet question (max 280 chars) |
expectedUserCount | number | Yes | Maximum participants |
minimumVoteCount | number | Yes | Votes required for resolution |
isCreatorResolver | boolean | Yes | If true, creator can resolve without votes |
signers | Keypair[] | Yes | Transaction signers |
Returns: Promise<string> - Transaction signature
placeWagerV2()
Places a wager on a bet.
import { Outcome } from "@solworks/poll-sdk";
const txHash = await sdk.placeWagerV2({
bet: betPublicKey,
amount: 25,
side: Outcome.For,
signers: [wallet],
});Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
bet | PublicKey | Yes | Bet account address |
amount | number | No* | USDC amount (human-readable) |
rawAmount | number | No* | USDC amount (raw, 6 decimals) |
side | Outcome | Yes | Outcome.For or Outcome.Against |
signers | Keypair[] | Yes | Transaction signers |
*One of amount or rawAmount is required.
Returns: Promise<string> - Transaction signature
initiateVoteV2()
Starts the voting period for a bet.
const txHash = await sdk.initiateVoteV2({
bet: betPublicKey,
signers: [wallet],
});Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
bet | PublicKey | Yes | Bet account address |
signers | Keypair[] | Yes | Transaction signers |
Returns: Promise<string> - Transaction signature
placeVoteV2()
Casts a vote on a bet's outcome.
const txHash = await sdk.placeVoteV2({
bet: betPublicKey,
outcome: Outcome.For,
signers: [wallet],
});Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
bet | PublicKey | Yes | Bet account address |
outcome | Outcome | Yes | Vote for which outcome wins |
signers | Keypair[] | Yes | Transaction signers |
Returns: Promise<string> - Transaction signature
settleBetBatchV2()
Settles a bet in batches (for many participants).
const txHash = await sdk.settleBetBatchV2({
bet: betPublicKey,
batchNumber: 0,
usersPerBatch: 10,
signers: [wallet],
});Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
bet | PublicKey | Yes | Bet account address |
batchNumber | number | Yes | Which batch to settle (0-indexed) |
usersPerBatch | number | Yes | Users per batch |
signers | Keypair[] | Yes | Transaction signers |
Returns: Promise<string> - Transaction signature
closeBetV2()
Closes a bet and returns pool funds (admin only).
const txHash = await sdk.closeBetV2({
bet: betPublicKey,
signers: [wallet],
});tryCancelWagerV2()
Attempts to cancel your wager (if allowed).
const txHash = await sdk.tryCancelWagerV2({
bet: betPublicKey,
signers: [wallet],
});Properties
sdk.addresses
Address derivation helpers. See Addresses reference.
sdk.accounts
Account fetching helpers. See Accounts reference.
sdk.program
The underlying Anchor program instance.
sdk.connection
The Solana connection instance.
sdk.wallet
The wallet adapter instance.
Static Methods
SDK.convertRustEnumValueToString()
Converts Rust enum values to readable strings.
const statusString = SDK.convertRustEnumValueToString(bet.status);
console.log(statusString); // "Pending", "Resolving", etc.