Skip to main content

Coinflip

Use Coinflip when you want to build a standard heads-or-tails wager.

What the builder does

createBetTransaction('coinflip', options) builds the Move call for Suigar Coinflip and sends the reward object back to owner.

Required options

  • owner
  • coinType
  • stake
  • side: 'heads' | 'tails'

Shared optional options

  • cashStake
  • betCount
  • metadata
  • gasBudget
  • allowGasCoinShortcut

Example

const tx = client.suigar.tx.createBetTransaction('coinflip', {
owner: '0x123',
coinType: '0x2::sui::SUI',
stake: 1_000_000_000n,
side: 'tails',
});

Typical usage

The usual Coinflip flow is:

  1. read the live stake bounds for the selected coin
  2. let the player choose heads or tails
  3. build the transaction
  4. sign and execute it
  5. decode the resulting BetResultEvent if you want structured outcome data

Read current limits

If your app needs to validate stake before building the transaction, read the live onchain parameters first:

const parameters = await client.suigar.getGameParameters('coinflip', {
coinType: '0x2::sui::SUI',
});

console.log(parameters.min_stake);
console.log(parameters.max_stake);

This is the simplest pattern for:

  • showing the allowed stake range in a bet form
  • blocking stale client-side inputs before building the transaction
  • re-checking limits on the server before signing or forwarding a request

Notes

  • side: 'tails' is converted by the SDK into the boolean expected by the contract call.
  • metadata is optional and gets encoded into the keys and values arrays used on-chain.
  • reserved metadata keys such as partner and referrer are ignored with a warning when passed manually
  • if the client was registered with suigar({ partner: '0x...' }), partner attribution is added automatically
  • min_stake and max_stake come from the live coin-specific parameter object, so avoid hardcoding them in product code