Developer Hub
🔮 For applications
SDK
Watch Hooks
useOdds

This hook is used to calculate the total odds before a bet is placed. These are the odds at which the bet will be placed, not accounting for slippage. The total odds vary based on the bet amount and the chosen selections, as each selection can have its own settings for reinforcement and margin.

Usage

⚠️

Before utilizing useOdds, it is essential to initialize event watchers and the SocketProvider:

  import { ChainProvider, SocketProvider, useWatchers } from '@azuro-org/sdk'
 
  export function Watchers() {
    useWatchers()
 
    return null
  }
 
  function Providers(props: { children: React.ReactNode }) {
    const { children } = props
 
    return (
      <ChainProvider>
        <SocketProvider>
          {children}
        </SocketProvider>
        <Watchers />
      </ChainProvider>
    )
  }

Provide selections and bet amount for calculating.

import { useOdds } from '@azuro-org/sdk'
 
const { odds, totalOdds, maxBet, loading } = useOdds({
  betAmount: '10',
  selections: [
    {
      conditionId: '486903008559711340',
      outcomeId: '29',
      coreAddress: '0x34nsf41f...',
    },  
  ],
})
ℹ️

The odds is an object where the key combination is determined by the concatenation of conditionId and outcomeId:

odds[`${conditionId}-${outcomeId}`]
ℹ️

Except of Single and Combo bets for Batch bet we use different amount structure batchBetAmounts.

The batchBetAmounts is an object where the key combination is determined by the concatenation of conditionId and outcomeId, the value is bet amount for outcome:

const selectionAmount = batchBetAmounts[`${conditionId}-${outcomeId}`]
ℹ️

Example of usage: Obtain the total odds for the provided selections.

import { type MarketOutcome, useOdds } from '@azuro-org/sdk'
 
 
type TotalOddsProps = {
  outcomes: MarketOutcome[]
  betAmount: string
}
 
function TotalOdds(props: TotalOddsProps) {
  const { outcomes, betAmount } = props
 
  const { totalOdds } = useOdds({
    betAmount,
    selections: outcomes,
  })
 
  return (
    <span>{totalOdds}</span>
  )
}

Props

{
  selections: Selection[]
  betAmount?: string
  batchBetAmounts?: Record<string, string>
}
type Selection = {
  conditionId: string
  outcomeId: string
  coreAddress: string
}

Return Value

{
  loading: boolean
  odds: Record<string, number>
  totalOdds: number
  maxBet?: number
}