Use Freebets
To use a freebet, the user needs:
- See available freebet list (fetched from the azuro api) in the UI.
- Create a bet with selected freebet.
- Claim winnings.
Fetch available freebets
- To retrieve all user's
bonuses
use theuseBonuses
hook:
'use client'
import { useBonuses } from '@azuro-org/sdk'
import { BonusStatus } from '@azuro-org/toolkit'
import { useAccount } from 'wagmi'
const NewFreeBetsChecker: React.FC = () => {
const { address } = useAccount()
const { data: bonuses } = useBonuses({
account: address!,
affiliate: '0x...', // your affiliate address
query: {
enabled: Boolean(address),
},
})
const activeFreebets = bonuses?.filter((freebet) => {
return freebet.status === BonusStatus.Available
})
return (
// render freebets
)
}
- To get all
freebets
that can be used based on the provided bet information (selections
) use theuseAvailableFreebets
hook:
'use client'
import { useAvailableFreebets } from '@azuro-org/sdk'
import { useAccount } from 'wagmi'
const AvailableFreebets: React.FC = () => {
const { address } = useAccount()
const items = [...] // your stored betslip items
const { data: freebets } = useAvailableFreebets({
account: address!,
affiliate: '0x...', // your affiliate address
selections: items,
query: {
enabled: Boolean(address),
},
})
return (
// render available freebets
)
}
Using BetslipProvider
:
import { useDetailedBetslip } from '@azuro-org/sdk'
const SelectFreebet: React.FC = () => {
const {
freebets, selectedFreebet, selectFreebet,
isFreebetsFetching,
} = useDetailedBetslip()
// select specific freebet
const handleClick = () => {
selectFreebet(freebets[0])
}
return (
// render available freebets
)
}
Use freebet to place a bet
Pass selected freebet to the useBet
hook:
const BetButton: React.FC<BetButtonProps> = () => {
const { items, clear } = useBaseBetslip()
const { selectedFreebet } = useDetailedBetslip()
const { submit } = useBet({
..., // other props
freebet: selectedFreebet,
})
return (
<button onClick={submit}>Bet</button>
)
}
Use the Azuro Freebets API (opens in a new tab) to get info about new freebets distributed for the customers.
type Address = `0x${string}`
type Hex = `0x${string}`
enum RestFreebetStatus {
New = 'New',
Claimed = 'Claimed',
Redeemed = 'Redeemed',
Canceled = 'Canceled',
Reissued = 'Reissued',
Withdrawn = 'Withdrawn',
}
type RestFreebet = {
id: number
owner: Address
amount: string // raw '10000000'
minOdds: string // raw '10000000'
contractId: number
signature: Hex
expiresAt: number // unix timestamp in seconds
campaign: string
status: RestFreebetStatus
contract: {
id: number
affiliate: Address
chainId: string
freebetContractAddress: Address
decimals: number
}
}
const freebetFetcher = async (bettorAddress: string): Promise<RestFreebet[]> => {
const response = await axios.get<RestFreebet[]>('https://api.azuro.org/api/v1/public/freebets/list', {
params: {
owner: bettorAddress.toLowerCase(),
affiliate: '0x...', // your affiliate address
},
})
return response.data || []
}
Api returns all available to claim freebets for specified bettor (status: New
| Reissued
).
If you work in several chains, pay attention to handle it, api returns all available freebets from all supported chains.
You must validate that freebet.contract.chainId
is the same as current app chain before suggesting to use it for a bet.
Also validate that odds of selected outcome (including slippage) satisfies freebet.minOdds
.
Freebets are not acceptable for combo bets.
Use freebet to place a bet
If you're not familiar with generic logic around placing a bet, please read Guides section first.
To apply freebet, outcome.rawMinOdds
should be greater than freebet.minOdds
. The bet should be single - freebets aren't applicable to combo bets.
Please note that we provide you with the flexibility to distribute Freebets without a budget limitation. However, if your customers claim Freebets for an amount exceeding the freebet contract balance, they will encounter an error during the smart contract execution call.
import { ethers } from 'ethers'
if (BigInt(outcome.rawMinOdds) < BigInt(freebet.minOdds)) {
// outcome minOdds should be greater than freebet.minOdds
return
}
const data = ethers.utils.defaultAbiCoder.encode(
[ 'tuple(uint256, uint64)' ],
[ { conditionId, outcomeId } ]
)
const freebetContract = new Contract(freebet.contract.freebetContractAddress, freebetABI)
freebetContract.bet(
{
chainId: freebet.contract.chainId,
expiresAt: freebet.expiresAt,
amount: freebet.amount,
freeBetId: freebet.id,
minOdds: freebet.minOdds,
owner: account,
},
freebet.signature,
coreAddress,
conditionId,
outcomeId,
deadline,
outcome.rawMinOdds
)
Withdraw a winning freebet
When customer placed a freebet, it will become regular bet in their bet history.
The customer will only receive profit from the bet: bet.payout - bet.amount
, the body of bet (amount) will be returned to the freebet contract
To redeem a winning freebet, you should call freebet contract:
const freebetContract = new Contract(bet.freebet.freebetContractAddress, freebetABI)
const tx = await freebetContract.connect(signer).withdrawPayout(bet.freebet.freebetId)
All details about bet history and base logic of redeem, please read in Guides section: Bet history & Redeem Bets