Quick Start
Get up and running with the Poll SDK in 5 minutes — from wallet setup to settled bet.
Overview
This guide walks through the full betting lifecycle: SDK initialization, creating an onchain user, placing a bet, wagering, voting, and settling winnings.
1. Initialize the SDK
Create a connection and wallet, then build the SDK instance:
import { SDK } from "@solworks/poll-sdk";
import { Connection, Keypair } from "@solana/web3.js";
const connection = new Connection("RPC_URL");
const wallet = Keypair.generate();
const sdk = SDK.build({
connection,
wallet: {
publicKey: wallet.publicKey,
signTransaction: async (tx) => {
tx.sign(wallet);
return tx;
},
signAllTransactions: async (txs) => {
txs.forEach((tx) => tx.sign(wallet));
return txs;
},
},
});2. Create a program user
Every wallet interacting with the protocol needs an onchain user account. Create one:
const txHash = await sdk.createUser({
signers: [wallet],
});
console.log("User created:", txHash);3. Create a bet
Initialize a new prediction market with a question, expected participant count, and minimum votes for resolution:
const txHash = await sdk.initializeBetV2({
question: "Will Bitcoin hit $100k by end of 2026?",
expectedUserCount: 10,
minimumVoteCount: 2,
isCreatorResolver: false,
signers: [wallet],
});
console.log("Bet created:", txHash);4. Place a wager
Bet on an outcome using Outcome.For (Yes) or Outcome.Against (No). Amounts are in USDC:
import { Outcome } from "@solworks/poll-sdk";
const txHash = await sdk.placeWagerV2({
bet: betPublicKey,
amount: 10, // 10 USDC
side: Outcome.For,
signers: [wallet],
});
console.log("Wager placed:", txHash);5. Initiate voting
When the event is ready to resolve, start the voting period. Any participant can initiate:
const txHash = await sdk.initiateVoteV2({
bet: betPublicKey,
signers: [wallet],
});
console.log("Voting started:", txHash);6. Cast a vote
Each participant votes on the outcome. Once minimumVoteCount is reached with consensus, the bet moves to Resolved:
const txHash = await sdk.placeVoteV2({
bet: betPublicKey,
outcome: Outcome.For,
signers: [wallet],
});
console.log("Vote cast:", txHash);7. Settle the bet
Settlement distributes winnings in batches. For small groups one batch is sufficient:
const txHash = await sdk.settleBetBatchV2({
bet: betPublicKey,
batchNumber: 0,
usersPerBatch: 10,
signers: [wallet],
});
console.log("Bet settled, winnings distributed!");