Developer Hub
🔮 For applications
Guides & Tutorials
Cashout
Use Cashout

Use Cashout

Get available

Provides availability of cashout for conditions and outcomes.

Using the usePrecalculatedCashouts (opens in a new tab) hook:

import { usePrecalculatedCashouts, type Bet } from '@azuro-org/sdk'
 
type BetProps = {
  bet: Bet
}
 
const Bet: React.FC<BetProps> = ({ bet }) => {
  const {
    createdAt, status: graphBetStatus, amount, outcomes,
    payout, cashout, possibleWin, freebetId, txHash,
    isWin, isLose, isCanceled, isRedeemed, isCashedOut,
  } = bet
 
 
  const { data: cashoutData } = usePrecalculatedCashouts({
    bet,
  })
 
  const { cashoutAmount, isAvailable: isCashoutAvailable } = cashoutData || {}
 
  return (
    // render
  )
}

Get calculation

To perform a cashout, you first need to retrieve the calculation that includes detailed information about the cashout amount.

Using the useCashout (opens in a new tab) hook:

import { useCashout, type Bet } from '@azuro-org/sdk'
 
export type CashoutModalProps = {
  bet: Bet
}
 
const CashoutModal: CashoutModalProps = (props) => {
  const { bet } = props
 
  const { calculationQuery } = useCashout({
    bet
  })
 
  const { data, error, isFetching: isCalculationFetching, refetch } = calculationQuery
  const { cashoutAmount, approveExpiredAt } = data || {}
 
  return (
    // render
  )
}

Create cashout

Create a cashout based on the calculation from previous step.

Using the useCashout (opens in a new tab) hook:

import { useCashout, type Bet } from '@azuro-org/sdk'
 
export type CashoutModalProps = {
  bet: Bet
}
 
const CashoutModal: CashoutModalProps = (props) => {
  const { bet } = props
 
  const { submit } = useCashout({
    bet
  })
 
  return (
    <button onClick={submit}>Cashout</button>
  )
}

Exceptions:

export const CashoutExceptionResponses = {
  GET_CONDITIONS_ERROR: {
    code: 'cashout.get_conditions_error',
    message: "Can't get conditions",
  },
  CASHOUT_MULTIPLIER_NOT_FOUND: {
    code: 'cashout.cashout_multiplier_not_found',
    message: 'Cashout multiplier not found',
  },
  CASHOUT_MULTIPLIER_NOT_AVAILABLE: {
    code: 'cashout.cashout_multiplier_not_available',
    message: 'Cashout multiplier not available',
  },
  BET_NOT_FOUND: {
    code: 'cashout.bet_not_found',
    message: 'Bet not found',
  },
  BET_NOT_AVAILABLE_TO_CASHOUT: {
    code: 'cashout.bet_not_available_to_cashout',
    message: 'Bet not available to cashout',
  },
  ENVIRONMENT_NOT_AVAILABLE: {
    code: 'cashout.environment_not_available',
    message: 'Environment not available',
  },
  CALCULATION_NOT_FOUND: {
    code: 'cashout.calculation_not_found',
    message: 'Calculation not found',
  },
  CASHOUT_NOT_AVAILABLE: {
    code: 'cashout.cashout_not_available',
    message: 'Cashout not available',
  },
  CASHOUT_ORDER_ALREADY_EXISTS: {
    code: 'cashout.cashout_order_already_exists',
    message: 'Cashout order already exists',
  },
  BET_ALREADY_CASHOUTED: {
    code: 'cashout.bet_already_cashouted',
    message: 'Bet already cash-outed',
  },
  ORDER_NOT_FOUND: {
    code: 'cashout.order_not_found',
    message: 'Order not found',
  },
  SIGNATURE_NOT_VERIFIED: {
    code: 'cashout.owner_signature_not_verified',
    message: 'Owner signature not verified',
  },
};

Get cashout order

Using the getCashout (opens in a new tab) function:

import { getCashout } from '@azuro-org/toolkit'
 
const cashout = await getCashout({
  chainId: 137,
  orderId: createdCashout.id,
})

Error codes:

  BadData = 'BadData',
  Other = 'Other',
  RiskExceeded = 'RiskExceeded',
  BetAlreadyPaid = 'BetAlreadyPaid',
  BetAlreadyResolved = 'BetAlreadyResolved',
  BetOwnerSignatureExpired = 'BetOwnerSignatureExpired',
  BettingContractNotAllowed = 'BettingContractNotAllowed',
  InsufficientBalance = 'InsufficientBalance',
  InvalidBetOwnerSignature = 'InvalidBetOwnerSignature',
  InvalidOdds = 'InvalidOdds',
  InvalidOddsCount = 'InvalidOddsCount',
  NothingChanged = 'NothingChanged',