Initiate Voting

Start the resolution voting period for a bet.

What You'll Do

Initiate the voting phase to begin resolving a bet's outcome.

Prerequisites

  • A bet with wagers placed
  • You must have a wager on the bet (participant)

Initiate Vote

Use the initiateVoteV2 method:

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

const txHash = await sdk.initiateVoteV2({
  bet: betPublicKey,
  signers: [wallet],
});

console.log("Voting initiated:", txHash);

Check Bet Status

Verify the bet is now in resolving state:

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

const bet = await sdk.accounts.betV2.single(betPublicKey);

console.log("Bet Status:", bet.status);
console.log("Vote Initiated At:", new Date(bet.voteInitiatedAt.toNumber() * 1000));

if (bet.status === MarketStatus.Resolving) {
  console.log("Voting is now open!");
}

Who Can Initiate

  • Any participant with an active wager can initiate voting
  • The initiator is marked in the bet account
  • Only one initiation is needed
typescript
// Check your wager
const bet = await sdk.accounts.betV2.single(betPublicKey);
const myWager = bet.wagers.find((w) => w.user.equals(wallet.publicKey));

if (myWager) {
  console.log("Is Vote Initiator:", myWager.isVoteInitiator);
}

State Transition

text
Pending → Resolving → Resolved → Distributed
           ↑
    initiateVoteV2()

When voting is initiated:

1. Bet status changes from Pending to Resolving

2. voteInitiatedAt timestamp is recorded

3. Initiator's wager is marked with isVoteInitiator = true

4. All participants can now cast votes

When to Initiate

Consider initiating voting when:

  • The event being bet on has concluded
  • A deadline has passed
  • All expected wagers are placed
  • Participants agree outcome is determinable

What Happens

When you initiate voting:

1. Bet status transitions to Resolving

2. No new wagers can be placed

3. Vote collection begins

4. Timestamp is recorded for the vote start

Error Handling

typescript
try {
  await sdk.initiateVoteV2({
    bet: betPublicKey,
    signers: [wallet],
  });
} catch (error) {
  if (error.message.includes("already resolving")) {
    console.log("Voting already initiated");
  } else if (error.message.includes("no wager found")) {
    console.log("You must have a wager to initiate voting");
  } else if (error.message.includes("not pending")) {
    console.log("Bet is not in pending state");
  } else {
    throw error;
  }
}

Next Steps

With voting initiated, all participants can now cast their votes. Continue to learn how to cast a vote.