Creates a single (ordinary) bet by submitting signed bet data to the Azuro API.

This function sends the bet order to the relayer which will then place the bet on-chain.

Usage

import { getBetTypedData, createBet } from '@azuro-org/toolkit'
 
 
const typedData = getBetTypedData({
  account: '0xlkns...',
  clientData: {...},
  bet: {...},
})
 
const signature = await walletClient.data.signTypedData(typedData)
 
const createdOrder: CreateBetResponse = await createBet({
  clientData: {...},
  bet: {...},
  signature,
})

Props

{
  clientData: BetClientData
  bet: {
    conditionId: string | bigint
    outcomeId: string | number | bigint
    minOdds: string | bigint
    amount: string | bigint
    nonce: string | number | bigint
  }
  signature: Hex // signed typed data
  bonusId?: string // freebet id to place bet with
}
type BetClientData = {
  attention: string
  affiliate: Address
  core: Address
  expiresAt: number
  chainId: ChainId
  relayerFeeAmount: string
  isBetSponsored: boolean
  isFeeSponsored: boolean
  isSponsoredBetReturnable: boolean
}

Return Value

type CreateBetResponse = {
  id: string
  state: BetOrderState
  errorMessage?: string
  error?: string
}
 
/**
* Flow:
* Created → Placed → Sent → (Accepted | Rejected) → Settled
*
* Cancellation may occur at any point in the flow after "Created".
* */
enum BetOrderState {
  /** First status when created */
  Created = 'Created',
  /** Bet is included in the calculation of potential loss/wins */
  Placed = 'Placed',
  /** The relayer has been taken into processing to send the bet to the contracts */
  Sent = 'Sent',
  /** Bet successfully accepted in the contracts */
  Accepted = 'Accepted',
  /** An error occurred during the contracts checks */
  Rejected = 'Rejected',
  /** The process of canceling the bet. The bet placed in the contracts still has the "GraphBetStatus.Accepted" status */
  PendingCancel = 'PendingCancel',
  /** Cancellation error. The bet placed in the contracts still has the "GraphBetStatus.Accepted" status */
  CancelFailed = 'CancelFailed',
  /** Bet is canceled */
  Canceled = 'Canceled',
  /** The bet is settled (won or lost) */
  Settled = 'Settled',
}