Skip to Content
Developer HubGuides & TutorialsFreebetsUse Freebets

Use Freebets

To use a freebet, the user needs:

  1. See available freebet list (fetched from the azuro api) in the UI.
  2. Create a bet with selected freebet.
  3. Claim winnings.

Fetch available freebets

  1. To retrieve all user’s bonuses use the useBonuses hook:
'use client' import { useBonuses } from '@azuro-org/sdk' import { BonusStatus } from '@azuro-org/toolkit' import { useAccount } from 'wagmi' const NewFreeBetsChecker: React.FC = () => { const { address } = useAccount() const { data: bonuses } = useBonuses({ account: address!, affiliate: '0x...', // your affiliate address query: { enabled: Boolean(address), }, }) const activeFreebets = bonuses?.filter((freebet) => { return freebet.status === BonusStatus.Available }) return ( // render freebets ) }
  1. To get all freebets that can be used based on the provided bet information (selections) use the useAvailableFreebets hook:
'use client' import { useAvailableFreebets } from '@azuro-org/sdk' import { useAccount } from 'wagmi' const AvailableFreebets: React.FC = () => { const { address } = useAccount() const items = [...] // your stored betslip items const { data: freebets } = useAvailableFreebets({ account: address!, affiliate: '0x...', // your affiliate address selections: items, query: { enabled: Boolean(address), }, }) return ( // render available freebets ) }
ℹ️

Using BetslipProvider:

import { useDetailedBetslip } from '@azuro-org/sdk' const SelectFreebet: React.FC = () => { const { freebets, selectedFreebet, selectFreebet, isFreebetsFetching, } = useDetailedBetslip() // select specific freebet const handleClick = () => { selectFreebet(freebets[0]) } return ( // render available freebets ) }

Use freebet to place a bet

Pass selected freebet to the useBet hook:

import { useDetailedBetslip, useBet } from '@azuro-org/sdk' const BetButton: React.FC<BetButtonProps> = () => { const { selectedFreebet } = useDetailedBetslip() const { submit } = useBet({ ..., // other props freebet: selectedFreebet, }) return ( <button onClick={submit}>Bet</button> ) }

Withdraw a winning freebet

When customer placed a freebet, it will become regular bet in their bet history.

ℹ️

The isSponsoredBetReturnable of freebet field indicates whether the value of the freebet will be included in the winning amount. If it is true, the freebet amount will be paid as part of the winnings. If it is false, only the profit (excluding the freebet value) will be paid out.

Taking this into account, here’s an example of how to calculate a bet’s possible win:

const diff = freebet && freebet.params.isSponsoredBetReturnable ? +freebet.amount : 0 // bet possible win based on isSponsoredBetReturnable field const possibleWin = totalBetOdds * +betAmount - diff

To redeem winning freebet, you need to use the useRedeemBet hook

import { type Bet, useRedeemBet } from '@azuro-org/sdk' const { submit, isPending, isProcessing } = useRedeemBet() const bet: Bet = {...} const handleRedeem = async () => { try { await submit({ bets: [ bet ] }) } catch {} }
Last updated on