Retrieves bet order data by order ID from the Azuro API. Returns null if the bet order is not found.
Usage
import { getBet } from '@azuro-org/toolkit'
const orderId = '0x123...'
const chainId = 137
const bet = await getBet({ chainId, orderId })
if (bet) {
console.log('Bet state:', bet.state)
console.log('Bet result:', bet.result)
}Props
{
chainId: ChainId
orderId: string
}Return Value
type GetBetResult = BetOrderData | nulltype BetOrderData = {
/** bettorAddressLowerCase_nonce */
id: string
state: BetOrderState
environment: Environment
betType: 'ORDINARY' | 'COMBO'
core: Address
bettor: Address
owner: Address
affiliate: Address
amount: number
payout: number | null
odds: number
bonusId: string | null
isFreebet: boolean
isSponsoredBetReturnable?: boolean
betId: number | null
txHash: Hex | null
margin: string
settledMargin: string | null
result: BetOrderResult | null
createdAt: ISOTimestamp
updatedAt: ISOTimestamp
settledAt: ISOTimestamp | null
redeemedAt: ISOTimestamp | null
conditions: BetOrderConditionData[]
meta: BetMetaData | null
error: string | null
errorMessage: string | null
}// It's very similar to the old v3Bet type from the GraphQL
type BetMetaData = {
/* graph id: `coreAddress_betId` */
id: string
core: {
type: 'V3'
address: Address
liquidityPool: {
address: Address
// bet token symbol - "USDT", "WETH", etc
asset: string
}
}
odds: string
betId: string
actor: Address
owner: Address
bettor: Address
nonce: string
amount: string
payout: null | string
result: BetResult | null
status: GraphBetStatus
rawOdds: string
affiliate: Address
rawAmount: string
rawPayout: null | string
isRedeemed: boolean
selections: Array<{
id: string
odds: string
result: SelectionResult | null
outcome: {
condition: {
id: string
gameId: string
status: ConditionStatus
outcomes: {
result: SelectionResult | null
outcomeId: string
sortOrder: number
}[]
conditionId: string
coreAddress: Address
wonOutcomeIds: null | string[]
_winningOutcomesCount: number
createdBlockTimestamp: string
resolvedBlockTimestamp: null | string
},
outcomeId: string
sortOrder: number
},
rawOdds: string
_outcomeId: string
}>
settledOdds: null | string
createdTxHash: Hex
rawSettledOdds: null | string
potentialPayout: string
potentialLossLimit: string
rawPotentialPayout: string
createdBlockTimestamp: string
rawPotentialLossLimit: string
resolvedBlockTimestamp: string | null
isCashedOut: boolean
isFreebetAmountReturnable: boolean | null
paymasterContractAddress: Address | null
redeemedTxHash: Hex | null
cashout: null | {
payout: string
}
}
export type BetOrderConditionData = {
conditionId: string
outcomeId: number
orderId: string
gameId: string
/**
* State of the game at the moment of bet placing, to determine whether the bet is Live or not.
* */
gameState: GameState.Live | GameState.Prematch
conditionMargin: string
selectionMargin: string
settledSelectionMargin: string | null
result: BetConditionStatus | null
/**
* Formatted odds of the condition, e.g. "1.55"
* */
price: string
/**
* Formatted amount,
* e.g. "18.5"
*
* in COMBO bets, it can have more fractional digits than bet token decimals,
* e.g. "18.057553956834532374" for 6 decimals USDT
* */
potentialAmount: string | null
potentialLoss: string | null
}
/**
* Flow:
* Created → Placed → Sent → (Accepted | Rejected) → Settled
* Cancellation may occur at any point in the flow after "Created".
*
* To show aggregated states to the end user, use `getBetStatus` helper
* */
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',
}