npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@betswirl/sdk-core

v0.1.27

Published

VanillaJS library for Betswirl protocol

Readme

@betswirl/sdk-core

VanillaJS library to use Betswirl protocol

Documentation

Installation

npm i @betswirl/sdk-core viem @apollo/client

Usage

1.With an external BetSwirl client

Using the sdk with an external BetSwirl client helps you to reduce your codebase and use your favorite compatible viem wallet. Here is the list of available external clients:

The example below uses the BetSwirl Wagmi client.

import { createConfig } from "@wagmi/core";
import { initWagmiBetSwirlClient} from "@betswirl/wagmi-provider";

  /* Init Wagmi BetSwirl client */
  const wagmiConfig = createConfig(...)

  const wagmiBetSwirlClient = initWagmiBetSwirlClient(wagmiConfig, {
    chainId: 137,
    affiliate: "0x...",
    gasPriceType: GAS_PRICE_TYPE.FAST,
    ...
  });

  /* Use the client */
  const casinoGames = await wagmiBetSwirlClient.getCasinoGames(false, 137);
  ...
  wagmiBetSwirlClient.playDice(77, ...)
  ...

2. With the native BetSwirl client (Viem)

Using the sdk with the native BetSwirl Viem client helps you to reduce your codebase. walletClient is optional if you only need to read data.

import { http, createWalletClient, createPublicClient } from "viem";
import { initViemBetSwirlClient } from "@betswirl/sdk-core";

  /* Create the Viem clients */
  const account = privateKeyToAccount("0x...");
  const transport = http("https://...")

  const publicClient = createPublicClient({
    chain: casinoChain.viemChain,
    transport,
  });

  const walletClient = createWalletClient({
    chain: casinoChain.viemChain,
    transport,
    account,
  })

  /* Create the native BetSwirl client */
  const viemBetSwirlClient = initViemBetSwirlClient(publicClient, walletClient, {
    chainId: 137,
    affiliate: "0x...",
    gasPriceType: GAS_PRICE_TYPE.FAST,
    ...
  })

  /* Use the native BetSwirl client */
  const casinoGames = await viemBetSwirlClient.getCasinoGames(false);
  ...
  viemBetSwirlClient.playDice(77, ...)
  ...

3. Without a client (only a wallet)

Using the sdk withtout a client doesn't let you to centralize all your options in one place. It's more appropriate for projects using only one or two sdk functions. The example below uses the BetSwirl viem wallet, which is native to the sdk. walletClient is optional if you only need to read data.

import { http, createWalletClient, createPublicClient } from "viem";
import { initViemBetSwirlClient } from "@betswirl/sdk-core";

  /* Create the Viem clients */
  const account = privateKeyToAccount("0x...");
  const transport = http("https://...")

  const publicClient = createPublicClient({
    chain: casinoChain.viemChain,
    transport,
  });

  const walletClient = createWalletClient({
    chain: casinoChain.viemChain,
    transport,
    account,
  })
  

  /* Create the native BetSwirl wallet */
  const viemBetSwirlWallet = new ViemBetSwirlWallet(publicClient, walletClient)

  /* Use functionalities with the wallet*/
  const casinoGames = await getCasinoGames(viemBetSwirlWallet, false);
  ...
  placeDiceBet(viemBetSwirlWallet, 77, ...)
  ...

4. Using function data

Getting function data doesn't require you to use a client or a wallet. It's particularly useful for frontend projects (React, Vue, etc) or IA agents plugins (Goat, AgentKit, Moxie, etc). The example below shows the placeBet function used in the Moxie BetSwirl plugin to place a bet.

import { MoxieWalletClient } from "@moxie-protocol/moxie-lib/src/wallet";
import {
    CASINO_GAME_TYPE,
    type CasinoChainId,
    GameEncodedInput,
    getPlaceBetFunctionData,
} from "@betswirl/sdk-core";
export async function placeBet(
    moxieWalletClient: MoxieWalletClient,
    game: CASINO_GAME_TYPE,
    gameEncodedInput: GameEncodedInput,
    gameMultiplier: number,
    casinoGameParams: {
        betAmount: bigint;
        betToken: Hex;
        betCount: number;
        receiver: Hex;
        stopGain: bigint;
        stopLoss: bigint;
    }
) {
    const chainId = Number(
        (await moxieWalletClient.wallet.provider.getNetwork()).chainId
    ) as CasinoChainId;
    // getBetRequirements is a custom function built in the BetSwirl plugin
    const betRequirements = await getBetRequirements(
        moxieWalletClient,
        game,
        casinoGameParams.betToken,
        gameMultiplier
    );

    if (!betRequirements.isAllowed) {
        throw new Error(`The token isn't allowed for betting`);
    }

    if (casinoGameParams.betAmount > betRequirements.maxBetAmount) {
        throw new Error(
            `Bet amount should be less than ${betRequirements.maxBetAmount}`
        );
    }
    if (casinoGameParams.betCount > betRequirements.maxBetCount) {
        throw new Error(
            `Bet count should be less than ${betRequirements.maxBetCount}`
        );
    }

    const functionData = getPlaceBetFunctionData(
        {
            betAmount: casinoGameParams.betAmount,
            game,
            gameEncodedInput: gameEncodedInput,
            receiver: casinoGameParams.receiver,
            betCount: casinoGameParams.betCount,
            tokenAddress: casinoGameParams.betToken,
            stopGain: casinoGameParams.stopGain,
            stopLoss: casinoGameParams.stopLoss,
        },
        chainId
    );

    try {
        const gasPrice =
            ((await moxieWalletClient.wallet.provider.getFeeData()).gasPrice *
                120n) /
            100n;

    // getChainlinkVrfCost is a custom function built in the BetSwirl plugin
        const vrfCost =
            (await getChainlinkVrfCost(
                moxieWalletClient,
                game,
                casinoGameParams.betToken,
                casinoGameParams.betCount,
                gasPrice
            ))
        const { hash: betHash } = await moxieWalletClient.sendTransaction(
            chainId.toString(),
            {
                toAddress: functionData.data.to,
                data: functionData.encodedData,
                value: functionData.extraData.getValue(vrfCost)
                gasPrice: Number(gasPrice),
            }
        );

        return betHash as Hex;
    } catch (error) {
        throw new Error(
            `An error occured while placing the bet: $${error.shortMessage || error.message}`
        );
    }
}

Examples