Developer Hub
🔮 For applications
Guides & Tutorials
Freebets
Use Freebets

Use Freebets

To use a freebet, the user needs:

  1. See available freebet list (fetched from the azuro api) in the UI.
  2. Call the bet function on the Freebet contract with data from available freebet.
  3. To claim their winnings or refunds if the condition was canceled users should call the withdrawPayout function.

Fetch available freebets

Use the Azuro Freebets API (opens in a new tab) to get info about new freebets distributed for the customers.

type Address = `0x${string}`
type Hex = `0x${string}`
 
enum RestFreebetStatus {
  New = 'New',
  Claimed = 'Claimed',
  Redeemed = 'Redeemed',
  Canceled = 'Canceled',
  Reissued = 'Reissued',
  Withdrawn = 'Withdrawn',
}
 
type RestFreebet = {
  id: number
  owner: Address
  amount: string // raw '10000000'
  minOdds: string // raw '10000000'
  contractId: number
  signature: Hex
  expiresAt: number // unix timestamp in seconds
  campaign: string
  status: RestFreebetStatus
  contract: {
    id: number
    affiliate: Address
    chainId: string
    freebetContractAddress: Address
    decimals: number
  }
}
 
const freebetFetcher = async (bettorAddress: string): Promise<RestFreebet[]> => {
  const response = await axios.get<RestFreebet[]>('https://api.azuro.org/api/v1/public/freebets/list', {
    params: {
      owner: bettorAddress.toLowerCase(),
      affiliate: '0x...', // your affiliate address
    },
  })
 
  return response.data || []
}

Api returns all available to claim freebets for specified bettor (status: New | Reissued).

⚠️

If you work in several chains, pay attention to handle it, api returns all available freebets from all supported chains. You must validate that freebet.contract.chainId is the same as current app chain before suggesting to use it for a bet. Also validate that odds of selected outcome (including slippage) satisfies freebet.minOdds.

🚨

Freebets are not acceptable for combo bets.

Use freebet to place a bet

If you're not familiar with generic logic around placing a bet, please read Guides section first.

⚠️

To apply freebet, outcome.rawMinOdds should be greater than freebet.minOdds. The bet should be single - freebets aren't applicable to combo bets.

⚠️

Please note that we provide you with the flexibility to distribute Freebets without a budget limitation. However, if your customers claim Freebets for an amount exceeding the freebet contract balance, they will encounter an error during the smart contract execution call.

import { ethers } from 'ethers'
 
if (BigInt(outcome.rawMinOdds) <  BigInt(freebet.minOdds)) {
  // outcome minOdds should be greater than freebet.minOdds
  return
}
 
const data = ethers.utils.defaultAbiCoder.encode(
  [ 'tuple(uint256, uint64)' ],
  [ { conditionId, outcomeId } ]
)
 
const freebetContract = new Contract(freebet.contract.freebetContractAddress, freebetABI)
 
freebetContract.bet(
  {
    chainId: freebet.contract.chainId,
    expiresAt: freebet.expiresAt,
    amount: freebet.amount,
    freeBetId: freebet.id,
    minOdds: freebet.minOdds,
    owner: account,
  },
  freebet.signature,
  coreAddress,
  conditionId,
  outcomeId,
  deadline,
  outcome.rawMinOdds
)

Withdraw a winning freebet

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

ℹ️

The customer will only receive profit from the bet: bet.payout - bet.amount, the body of bet (amount) will be returned to the freebet contract

To redeem a winning freebet, you should call freebet contract:

const freebetContract = new Contract(bet.freebet.freebetContractAddress, freebetABI)
 
const tx = await freebetContract.connect(signer).withdrawPayout(bet.freebet.freebetId)

All details about bet history and base logic of redeem, please read in Guides section: Bet history & Redeem Bets