Developer Hub
🔮 For applications
SDK
Write Hooks
usePrepareBet

This hook is used for users to place bets and approve the use tokens for payment when needed.

Usage

import { usePrepareBet } from '@azuro-org/sdk'
 
// using BetslipProvider
import { useBaseBetslip, useDetailedBetslip } from '@azuro-org/sdk'
 
const { items, clear } = useBaseBetslip()
const { betAmount, odds, totalOdds } = useDetailedBetslip()
 
// using useOdds
import { useOdds } from '@azuro-org/sdk'
 
const [ betAmount, setBetAmount ] = useState()
const items = [...]
const { odds, totalOdds } = useOdds({ betAmount, selections })
 
const {
  isAllowanceLoading,
  isApproveRequired,
  submit,
  approveTx,
  betTx,
} = usePrepareBet({
  betAmount,
  slippage: 10, // 10%
  affiliate: '0x...', // your affiliate address
  selections: items,
  odds,
  totalOdds,
  onSuccess: () => {
    clear()
  },
})
 
submit()
ℹ️

When allowing users to place express (or combo) bets, you can pass multiple selections, each for different outcomes across various events, and combine them into one larger bet.

const {...} = usePrepareBet({
  betAmount: '10',
  slippage: 5,
  affiliate: '0x...',
  selections: [
    {
      conditionId: '486903008559711340',
      outcomeId: '29',
      coreAddress: '0x34nsf41f...',
    },
    {
      conditionId: '486903008559711341',
      outcomeId: '30',
      coreAddress: '0x34nsf41f...',
    },
  ],
  odds,
  totalOdds,
})

Props

{
  betAmount: string // bet amount
  slippage: number // in percent
  affiliate: Address // your affiliate address
  odds: Record<string, number>, // odds
  totalOdds: number, // total odds
  selections: Selection[] // user's choise for bet
  liveEIP712Attention?: string // attention text for eip-712 sign (up to 160 chars)
  deadline?: number // duration after which the bet will be canceled if it does not get included in a block
  onSuccess?(receipt: TransactionReceipt): void // callback function triggered after a successful bet
  onError?(err?: Error): void // callback function triggered upon encountering an error
}
type Selection = {
  conditionId: string
  outcomeId: string
  coreAddress: string
}

Return Value

{
  isAllowanceLoading: boolean // flag indicates the fetching of allowance
  isApproveRequired: boolean // flag indicates the necessity for token spending approval
  isRelayerFeeLoading: boolean // flag indicates the fetching of relayer fee for live bet
  submit: () => Promise<TransactionReceipt> // function used to trigger the bet action or token spending approval
  relayerFeeAmount: string | undefined // relayer fee amount for live bet
  approveTx: { // approve transaction state
    isPending: boolean
    isProcessing: boolean
  }
  betTx: { // bet transaction state
    isPending: boolean
    isProcessing: boolean
  }
}