Client Functions
This page lists all functions accessible from a BetSwirl client. These functions are particularly useful if you’re using one of the two available clients:
- External BetSwirl Client (Wagmi) - For multi-chain applications with Wagmi
- Native BetSwirl Client (Viem) - For simple applications with Viem
100% of the functions below are also available without using a client.
Bet Read Functions
getCasinoGames
bet-readDescription: Retrieves the list of available casino games on a specific chain.
💡Tips: Use this function to display available games in your user interface. Pass "true" to get only the active games.
const games = await wagmiBetSwirlClient.getCasinoGames(true, 137);getCasinoTokens
bet-readDescription: Retrieves the list of available tokens for betting on a specific chain.
💡Tips: Pass "true" to get only the active tokens. (inactive token means you can't bet with it for the moment)
// Get all tokens
const tokens = await client.getCasinoTokens(false);
// Get only active tokens
const activeTokens = await client.getCasinoTokens(true);getCasinoGameToken
bet-readDescription: Retrieves specific token information for a game, including house edge and affiliate settings.
💡Tips: "affiliateHouseEdge" is particularly useful to get the possible choice inputs for the game (it allows to calculate the net multipliers).
// Get token info for a specific game
const gameToken = await client.getCasinoGameToken(
casinoToken,
CASINO_GAME_TYPE.DICE,
affiliateAddress
);getBetRequirements
bet-readDescription: Retrieves betting requirements for a specific token and game.
💡Tips: Use this function to validate bet parameters before placing a bet.
// Get bet requirements
const requirements = await client.getBetRequirements(
token,
multiplier,
CASINO_GAME_TYPE.DICE
);getChainlinkVrfCost
bet-readDescription: Calculates the Chainlink VRF cost for a particular bet.
💡Tips: We highly recommend you multiply this value by x1.1 - x1.2 (buffer) to reduce the number of failed txns due to gas price peaks.
// Calculate VRF cost
const vrfCost = await client.getChainlinkVrfCost(
CASINO_GAME_TYPE.DICE,
tokenAddress,
betCount
);getKenoConfiguration
bet-readDescription: Retrieves the keno configuration for a specific token.
💡Tips: Each token has its own keno configuration, it's important to get the correct configuration for the token you're betting with.
// Get keno configuration
const kenoConfig = await client.getKenoConfiguration(token);getWeightedGameConfiguration
bet-readDescription: Retrieves weighted game configuration by ID.
💡Tips: Use this function to get configuration for wheel, plinko, or custom weighted games.
// Get weighted game configuration
const config = await client.getWeighedGameConfiguration(configId);Bet Action Functions
playDice
bet-actionDescription: Places a bet on the dice game with specified parameters.
💡Tips: Make sure to validate parameters before calling this function. If an approval is needed, it will be automatically handled by the SDK.
// Place dice bet
const result = await client.playDice({
cap: 50,
betAmount: parseEther("0.1"),
betToken: "0x...",
receiver: userAddress,
});playCoinToss
bet-actionDescription: Places a bet on the coin toss game with specified parameters.
💡Tips: Make sure to validate parameters before calling this function. If an approval is needed, it will be automatically handled by the SDK.
// Place coin toss bet
const result = await client.playCoinToss({
face: COINTOSS_FACE.HEADS,
betAmount: parseEther("0.1"),
betToken: "0x...",
receiver: userAddress,
});playRoulette
bet-actionDescription: Places a bet on the roulette game with specified parameters.
💡Tips: Make sure to validate parameters before calling this function. If an approval is needed, it will be automatically handled by the SDK.
// Place roulette bet
const result = await client.playRoulette({
numbers: [1, 2, 3],
betAmount: parseEther("0.1"),
betToken: "0x...",
receiver: userAddress
});playKeno
bet-actionDescription: Places a bet on the keno game with specified parameters.
💡Tips: Make sure to validate parameters before calling this function. If an approval is needed, it will be automatically handled by the SDK. You can get the keno configuration with the "getKenoConfiguration" function.
// Place keno bet
const result = await client.playKeno({
balls: [1, 5, 12, 23, 45],
kenoConfig: kenoConfiguration,
betAmount: parseEther("0.1"),
betToken: "0x...",
receiver: userAddress
});playWheel
bet-actionDescription: Places a bet on the wheel game with specified parameters.
💡Tips: Make sure to validate parameters before calling this function. If an approval is needed, it will be automatically handled by the SDK. You can get the weighted game configuration with the "getWeightedGameConfiguration" function.
// Place wheel bet
const result = await client.playWheel({
weightedGameConfig: wheelConfig,
betAmount: parseEther("0.1"),
betToken: "0x...",
receiver: userAddress
});playPlinko
bet-actionDescription: Places a bet on the plinko game with specified parameters.
💡Tips: Make sure to validate parameters before calling this function. If an approval is needed, it will be automatically handled by the SDK. You can get the weighted game configuration with the "getWeightedGameConfiguration" function.
// Place plinko bet
const result = await client.playPlinko({
weightedGameConfig: plinkoConfig,
betAmount: parseEther("0.1"),
betToken: "0x...",
receiver: userAddress
});playWeightedGame
bet-actionDescription: Places a bet on a custom weighted game with specified parameters.
💡Tips: Use this for custom games not in the list of weighted games. You can also use it for Wheel & Plinko.
// Place weighted game bet
const result = await client.playWeightedGame({
weightedGameConfig: customConfig,
game: CASINO_GAME_TYPE.CUSTOM_WEIGHTED_GAME,
betAmount: parseEther("0.1"),
betToken: "0x...",
receiver: userAddress
});waitDice
bet-actionDescription: Waits for a dice bet to be rolled and returns the result.
💡Tips: Use this function to wait for the bet result after placing a bet. It generally takes 3 to 15 seconds for a bet to be rolled.
// Wait for dice result
const { rolledBet, receipt } = await client.waitDice(
placedBet,
{ pollingInterval: 1000 }
);waitCoinToss
bet-actionDescription: Waits for a coin toss bet to be rolled and returns the result.
💡Tips: Use this function to wait for the bet result after placing a bet. It generally takes 3 to 15 seconds for a bet to be rolled.
// Wait for coin toss result
const { rolledBet, receipt } = await client.waitCoinToss(
placedBet,
{ pollingInterval: 1000 }
);waitRoulette
bet-actionDescription: Waits for a roulette bet to be rolled and returns the result.
💡Tips: Use this function to wait for the bet result after placing a bet. It generally takes 3 to 15 seconds for a bet to be rolled.
// Wait for roulette result
const { rolledBet, receipt } = await client.waitRoulette(
placedBet,
{ pollingInterval: 1000 }
);waitKeno
bet-actionDescription: Waits for a keno bet to be rolled and returns the result.
💡Tips: Use this function to wait for the bet result after placing a bet. It generally takes 3 to 15 seconds for a bet to be rolled.
// Wait for keno result
const { rolledBet, receipt } = await client.waitKeno(
placedBet,
{ pollingInterval: 1000 }
);waitWheel
bet-actionDescription: Waits for a wheel bet to be rolled and returns the result.
💡Tips: Use this function to wait for the bet result after placing a bet. It generally takes 3 to 15 seconds for a bet to be rolled.
// Wait for wheel result
const { rolledBet, receipt } = await client.waitWheel(
placedBet,
weightedGameConfig,
houseEdge,
{ pollingInterval: 1000 }
);waitPlinko
bet-actionDescription: Waits for a plinko bet to be rolled and returns the result.
💡Tips: Use this function to wait for the bet result after placing a bet. It generally takes 3 to 15 seconds for a bet to be rolled.
// Wait for plinko result
const { rolledBet, receipt } = await client.waitPlinko(
placedBet,
weightedGameConfig,
houseEdge,
{ pollingInterval: 1000 }
);Bet History Functions
fetchBets
bet-historyDescription: Retrieves betting history with filtering and pagination options.
💡Tips: Perfect for displaying betting history in a user dashboard with advanced filtering.
// Get user bets with filters
const { bets, error } = await client.fetchBets(137, {
bettor: userAddress,
game: CASINO_GAME_TYPE.DICE,
status: "completed"
}, 1, 10);fetchBet
bet-historyDescription: Retrieves a specific bet by its ID.
// Get specific bet
const { bet, error } = await client.fetchBet("123", 137);fetchBetByHash
bet-historyDescription: Retrieves a specific bet by its transaction hash.
// Get bet by transaction hash
const { bet, error } = await client.fetchBetByHash(
"0x123...",
137
);Freebet Functions
fetchFreebets
freebetDescription: Retrieves available (non-expired) freebets for a player.
💡Tips: Pass "withExternalBankrollFreebets" as true to also get the "sponsored" freebets (freebets created by the bankroll managers).
// Get user freebets
const freebets = await client.fetchFreebets(
userAddress,
[affiliateAddress],
[chainId],
false
);fetchFreebetCampaigns
freebetDescription: Retrieves freebet campaigns with filtering and pagination.
💡Tips: This function is for admin purposes only. There is a good chance you don't need to use it.
// Get freebet campaigns
const { campaigns, total } = await client.fetchFreebetCampaigns(
10, 0, FREEBET_CAMPAIGN_STATUS.PENDING, affiliateAddress, 137
);fetchFreebetCampaign
freebetDescription: Retrieves a specific freebet campaign by its ID.
💡Tips: This function is for admin purposes only. There is a good chance you don't need to use it
// Get specific freebet campaign
const campaign = await client.fetchFreebetCampaign(123);fetchFreebetCodeCampaigns
freebetDescription: Retrieves freebet code campaigns with filtering and pagination.
💡Tips: This function is for admin purposes only. There is a good chance you don't need to use it.
// Get freebet code campaigns
const { campaigns, total } = await client.fetchFreebetCodeCampaigns(
10, 0, FREEBET_CAMPAIGN_STATUS.PENDING, affiliateAddress, 137
);fetchFreebetCodeCampaign
freebetDescription: Retrieves a specific freebet code campaign by its ID.
💡Tips: This function is for admin purposes only. There is a good chance you don't need to use it
// Get specific freebet code campaign
const campaign = await client.fetchFreebetCodeCampaign(123);playFreebetDice
freebetDescription: Places a freebet on the dice game.
💡Tips: Use this function to place a bet using a freebet instead of user tokens. Only a single bet (betCount = 1) can be placed with a freebet.
// Place freebet dice
const result = await client.playFreebetDice({
freebet: signedFreebet,
cap: 50,
});playFreebetCoinToss
freebetDescription: Places a freebet on the coin toss game.
💡Tips: Use this function to place a bet using a freebet instead of user tokens. Only a single bet (betCount = 1) can be placed with a freebet.
// Place freebet coin toss
const result = await client.playFreebetCoinToss({
freebet: signedFreebet,
face: COINTOSS_FACE.HEADS,
});playFreebetRoulette
freebetDescription: Places a freebet on the roulette game.
💡Tips: Use this function to place a bet using a freebet instead of user tokens. Only a single bet (betCount = 1) can be placed with a freebet.
// Place freebet roulette
const result = await client.playFreebetRoulette({
freebet: signedFreebet,
numbers: [1, 2, 3],
});playFreebetKeno
freebetDescription: Places a freebet on the keno game.
💡Tips: Use this function to place a bet using a freebet instead of user tokens. Only a single bet (betCount = 1) can be placed with a freebet.
// Place freebet keno
const result = await client.playFreebetKeno({
freebet: signedFreebet,
balls: [1, 5, 12, 23, 45],
kenoConfig: kenoConfiguration,
});playFreebetWheel
freebetDescription: Places a freebet on the wheel game.
💡Tips: Use this function to place a bet using a freebet instead of user tokens. Only a single bet (betCount = 1) can be placed with a freebet.
// Place freebet wheel
const result = await client.playFreebetWheel({
freebet: signedFreebet,
weightedGameConfig: wheelConfig,
});playFreebetPlinko
freebetDescription: Places a freebet on the plinko game.
💡Tips: Use this function to place a bet using a freebet instead of user tokens. Only a single bet (betCount = 1) can be placed with a freebet.
// Place freebet plinko
const result = await client.playFreebetPlinko({
freebet: signedFreebet,
weightedGameConfig: plinkoConfig,
});playFreebetWeightedGame
freebetDescription: Places a freebet on a custom weighted game.
💡Tips: Use this function to place a bet using a freebet instead of user tokens. Only a single bet (betCount = 1) can be placed with a freebet. You can use it for Wheel & Plinko.
// Place freebet weighted game
const result = await client.playFreebetWeightedGame({
freebet: signedFreebet,
weightedGameConfig: customConfig,
game: CASINO_GAME_TYPE.CUSTOM_WEIGHTED_GAME,
});Leaderboard Functions
fetchLeaderboards
leaderboardDescription: Retrieves available leaderboards and tournaments with filtering options.
💡Tips: By passing playerAddress, you can get the leaderboard ranking of the specific player.
// Get leaderboards
const { leaderboards, total } = await client.fetchLeaderboards(
10, 0, playerAddress, [affiliateAddress], [137]
);fetchLeaderboard
leaderboardDescription: Retrieves a specific leaderboard by its ID.
💡Tips: By passing playerAddress, you can get the leaderboard ranking of the specific player.
// Get specific leaderboard
const leaderboard = await client.fetchLeaderboard(123, playerAddress);getLeaderboardClaimableAmount
leaderboardDescription: Retrieves the claimable amount for a player on a specific leaderboard.
💡Tips: Use this function to check if a player has rewards to claim (to save resources, only call it if the leaderboard is finalized AND the player is in the winners list of the leaderboard).
// Get claimable amount
const claimableAmount = await client.getLeaderboardClaimableAmount(
leaderboardOnChainId, // on-chain ID
playerAddress,
chainId
);claimLeaderboardRewards
leaderboardDescription: Claims rewards from a leaderboard for a specific receiver address.
💡Tips: The rewards can be claimed only if the leaderboard status is "finalized".
// Claim leaderboard rewards
const { receipt, result } = await client.claimLeaderboardRewards(
leaderboard,
receiverAddress,
(tx, result) => console.log("Claim pending:", tx)
);refreshLeaderboardsWithBets
leaderboardDescription: Refreshes leaderboards with new bet data.
💡Tips: Use this function to update leaderboard data after placing bets.
// Refresh leaderboards
const success = await client.refreshLeaderboardsWithBets(
betIds,
chainId,
LEADERBOARD_TYPE.CASINO
);fetchAffiliateLeaderboards
leaderboardDescription: Retrieves leaderboards for a specific affiliate with filtering options.
💡Tips: This function is for admin purposes only. There is a good chance you don't need to use it.
// Get affiliate leaderboards
const { leaderboards, total } = await client.fetchAffiliateLeaderboards(
affiliateAddress,
10, 0, 137
);fetchAffiliateLeaderboard
leaderboardDescription: Retrieves a specific affiliate leaderboard by its ID.
💡Tips: this function is for admin purposes only. There is a good chance you don't need to use it.
// Get specific affiliate leaderboard
const leaderboard = await client.fetchAffiliateLeaderboard(123);Analytics Functions
fetchTokens
analyticsDescription: Retrieves token information from the subgraph with pagination.
💡Tips: Use this function to get comprehensive token data from the blockchain.
// Get tokens with pagination
const { tokens, error } = await client.fetchTokens(137, 1, 20);fetchToken
analyticsDescription: Retrieves specific token information by address.
💡Tips: Use this function to get detailed information about a specific token.
// Get specific token
const { token, error } = await client.fetchToken(
"0x123...",
137
);