SDK Class

Complete reference for the SDK class — the primary entry point for the Poll protocol.

Overview

The SDK class is the main entry point for interacting with the Poll.fun betting protocol. Use SDK.build() to create an instance, then call methods to submit transactions or fetch accounts.

SDK.build()

Creates a new SDK instance.

typescript
import { SDK } from "@solworks/poll-sdk";
import { Connection } from "@solana/web3.js";

const sdk = SDK.build({
  connection: new Connection("https://api.mainnet-beta.solana.com"),
  wallet: walletAdapter,
  skipPreflight: false,
  commitment: "confirmed",
  maxRetries: 5,
});
NameTypeRequiredDescription
connectionConnectionYesSolana RPC connection
walletIWalletNoWallet adapter for signing
skipPreflightbooleanNoSkip preflight transaction checks
commitmentCommitmentNoTransaction confirmation level
maxRetriesnumberNoMax transaction retry attempts

User methods

createUser()

Creates an onchain program user account for a wallet.

typescript
const txHash = await sdk.createUser({
  signers: [wallet],
});
NameTypeRequiredDescription
signersKeypair[]YesTransaction signers
payerOverridePublicKeyNoOverride fee payer
confirmOptionsConfirmOptionsNoConfirmation options

Returns Promise<string> — transaction signature.

Bet methods (V2)

initializeBetV2()

Creates a new prediction market.

typescript
const txHash = await sdk.initializeBetV2({
  question: "Will Bitcoin hit $100k?",
  expectedUserCount: 10,
  minimumVoteCount: 2,
  isCreatorResolver: false,
  signers: [wallet],
});
NameTypeRequiredDescription
questionstringYesBet question (max 280 chars)
expectedUserCountnumberYesMaximum participants
minimumVoteCountnumberYesVotes required for resolution
isCreatorResolverbooleanYesIf true, creator can resolve without votes
signersKeypair[]YesTransaction signers

Returns Promise<string> — transaction signature.

placeWagerV2()

Places a USDC wager on a bet outcome.

typescript
import { Outcome } from "@solworks/poll-sdk";

const txHash = await sdk.placeWagerV2({
  bet: betPublicKey,
  amount: 25,
  side: Outcome.For,
  signers: [wallet],
});
NameTypeRequiredDescription
betPublicKeyYesBet account address
amountnumberNoUSDC amount (human-readable)
rawAmountnumberNoUSDC amount (raw, 6 decimals)
sideOutcomeYesOutcome.For or Outcome.Against
signersKeypair[]YesTransaction signers

Returns Promise<string> — transaction signature.

initiateVoteV2()

Starts the voting period for a bet.

typescript
const txHash = await sdk.initiateVoteV2({
  bet: betPublicKey,
  signers: [wallet],
});
NameTypeRequiredDescription
betPublicKeyYesBet account address
signersKeypair[]YesTransaction signers

Returns Promise<string> — transaction signature.

placeVoteV2()

Casts a vote on the bet's outcome.

typescript
const txHash = await sdk.placeVoteV2({
  bet: betPublicKey,
  outcome: Outcome.For,
  signers: [wallet],
});
NameTypeRequiredDescription
betPublicKeyYesBet account address
outcomeOutcomeYesVote for which outcome wins
signersKeypair[]YesTransaction signers

Returns Promise<string> — transaction signature.

settleBetBatchV2()

Settles a bet in batches and distributes winnings.

typescript
const txHash = await sdk.settleBetBatchV2({
  bet: betPublicKey,
  batchNumber: 0,
  usersPerBatch: 10,
  signers: [wallet],
});
NameTypeRequiredDescription
betPublicKeyYesBet account address
batchNumbernumberYesWhich batch to settle (0-indexed)
usersPerBatchnumberYesUsers per batch
signersKeypair[]YesTransaction signers

Returns Promise<string> — transaction signature.

Properties

sdk.addressesAddress derivation helpers for all PDAs. See Addresses reference.
sdk.accountsAccount fetching helpers with typed return values.
sdk.instructionsInstruction builders — get raw TransactionInstruction without broadcasting.
sdk.programThe underlying Anchor program instance.
sdk.connectionThe Solana RPC connection.
sdk.walletThe wallet adapter instance.

Static methods

SDK.convertRustEnumValueToString()

Converts raw Rust enum values (stored as objects on-chain) to readable strings.

typescript
const statusString = SDK.convertRustEnumValueToString(bet.status);
console.log(statusString); // "Pending", "Resolving", etc.