Quick Start
Get up and running with the Poll SDK in 5 minutes.
Overview
This guide walks you through creating a complete betting flow: from wallet setup to settling a bet.
1. Initialize the SDK
First, set up your connection and wallet:
typescript
import { SDK } from "@solworks/poll-sdk";
import { Connection, Keypair, LAMPORTS_PER_SOL } 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. Fund Your Wallet with SOL and USDC
Send USDC to the wallet address.
3. Create a Program User
Initialize your onchain user account:
typescript
const createUserTx = await sdk.createUser({
signers: [wallet],
});
console.log("User created:", createUserTx);4. Create a Bet
Initialize a new prediction market:
typescript
const createBetTx = await sdk.initializeBetV2({
question: "Will Bitcoin hit $100k by end of 2026?",
expectedUserCount: 2,
minimumVoteCount: 2,
isCreatorResolver: false,
signers: [wallet],
});
console.log("Bet created:", createBetTx);5. Place a Wager
Bet on the outcome:
typescript
import { Outcome } from "@solworks/poll-sdk";
const wagerTx = await sdk.placeWagerV2({
bet: betPublicKey,
amount: 10, // 10 USDC
side: Outcome.For, // Betting "Yes"
signers: [wallet],
});
console.log("Wager placed:", wagerTx);6. Initiate Voting
When ready to resolve, start the voting period:
typescript
const initVoteTx = await sdk.initiateVoteV2({
bet: betPublicKey,
signers: [wallet],
});
console.log("Voting started:", initVoteTx);7. Cast Your Vote
Submit your vote for the outcome:
typescript
const voteTx = await sdk.placeVoteV2({
bet: betPublicKey,
outcome: Outcome.For,
signers: [wallet],
});
console.log("Vote cast:", voteTx);8. Settle the Bet
Once consensus is reached, settle and distribute winnings:
typescript
const settleTx = await sdk.settleBetBatchV2({
bet: betPublicKey,
batchNumber: 0,
usersPerBatch: 10,
signers: [wallet],
});
console.log("Bet settled, winnings distributed!");Complete Example
See the full working example on GitHub or continue to individual guides for detailed explanations of each step.