Skip to Content
BetSwirl Affliate program is released 🎉
Developer Hub⚙️ SDKsCoreClient functions

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:

100% of the functions below are also available without using a client.


Bet Read Functions

getCasinoGames

bet-read

Description: 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-read

Description: 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-read

Description: 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-read

Description: 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-read

Description: 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-read

Description: 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-read

Description: 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-action

Description: 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-action

Description: 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-action

Description: 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-action

Description: 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-action

Description: 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-action

Description: 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-action

Description: 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-action

Description: 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-action

Description: 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-action

Description: 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-action

Description: 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-action

Description: 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-action

Description: 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-history

Description: 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-history

Description: Retrieves a specific bet by its ID.

// Get specific bet const { bet, error } = await client.fetchBet("123", 137);

fetchBetByHash

bet-history

Description: Retrieves a specific bet by its transaction hash.

// Get bet by transaction hash const { bet, error } = await client.fetchBetByHash( "0x123...", 137 );

Freebet Functions

fetchFreebets

freebet

Description: 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

freebet

Description: 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

freebet

Description: 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

freebet

Description: 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

freebet

Description: 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

freebet

Description: 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

freebet

Description: 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

freebet

Description: 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

freebet

Description: 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

freebet

Description: 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

freebet

Description: 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

freebet

Description: 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

leaderboard

Description: 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

leaderboard

Description: 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

leaderboard

Description: 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

leaderboard

Description: 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

leaderboard

Description: 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

leaderboard

Description: 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

leaderboard

Description: 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

analytics

Description: 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

analytics

Description: 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 );
Last updated on