Place a bet
Estimate, place, and reconcile a market bet on the Bento markets host.
By the end: you'll have estimated a bet, placed it, and read your position back.
Prerequisites
- Markets host URL (
baseUrl) - Wallet auth headers configured on
createBentoSdk - Funded managed account (testnet: auto-mint faucet after register/login)
- For private markets: you must be a member (creator, or join via invite with
duelInvitations.userJoin) beforeplaceBet— see Create a market
Flow
import { createBentoSdk, walletAuthProvider } from '@bento.fun/sdk';
const sdk = createBentoSdk({
baseUrl: process.env.BENTO_URL!,
// markets auth is a Bearer JWT from eoaLogin (see Authentication)
auth: walletAuthProvider(() => ({ Authorization: `Bearer ${token}` })),
});
// 1. Estimate (optionIndex is 0|1; amount is collateral wei)
// Platform minimum bet is **5** collateral units, in the collateral's decimals
// (18 for credits / BSC USDC, 6 for Base USDC).
// `estimateBuy` does not enforce the floor: a sub-5 amount can quote then 500 at place.
const stake = '10000000000000000000'; // 10 units
const est = await sdk.user.bets.estimateBuy({
duelId: 'your-duel-id',
optionIndex: 0,
betAmountUsdc: stake,
slippageBps: 100,
});
if (!est.success) throw new Error('estimate rejected'); // narrows est to the success variant
// 2. Place (HTTP acceptance). Use `placeBetFromEstimate`: it maps the quote's
// fields to the request and derives the slippage floor from `sharesOut`. Do NOT
// hand-build the request from `estimate.min_shares_out`: on larger bets the engine
// returns it ABOVE `sharesOut`, which empties the server's slippage window and 400s
// the bet with "Slippage exceeded".
// `bet` is the option label: `YES` / `NO` for prediction, the `optionA` / `optionB`
// text for versus. Pass `tokenDecimals` so the SDK rejects sub-5 amounts client-side.
await sdk.user.placeBetFromEstimate(
{
estimate: est.estimate,
duelId: 'your-duel-id',
duelType: 'PREDICTION', // or 'VERSUS'
bet: 'YES',
optionIndex: 0,
betAmount: stake,
betAmountUsdc: stake,
slippageBps: 100,
tokenDecimals: 18, // your collateral's decimals
},
{ idempotencyKey },
);
// 3. Reconcile (field is `address`, not `walletAddress`)
const shares = await sdk.user.bets.getUserShares({
duelId: 'your-duel-id',
address: walletAddress,
});Related
- Create a market: public create, private invite/join
- Mutation semantics
- TypeScript SDK:
sdk.user.bets