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

@hellomoon/camelot-sdk

v0.1.0

Published

TypeScript SDK for the Mooncast API with Switchboard on-demand randomness

Readme

@hellomoon/camelot-sdk

TypeScript SDK for the Mooncast API — auth, read endpoints, transaction building, and a live WebSocket feed. Flip and settle transactions are automatically wrapped with the required Switchboard on-demand randomness instructions (commit / reveal), so you get ready-to-sign transactions.

Everything is exported under the coinflip namespace.

Installation

npm install @hellomoon/camelot-sdk @solana/web3.js @switchboard-xyz/on-demand @coral-xyz/anchor

Quick start

import { coinflip } from "@hellomoon/camelot-sdk";
import { Connection } from "@solana/web3.js";

const client = new coinflip.MooncastSdk({
  apiUrl: "https://api.mooncast.example",
  connection: new Connection("https://api.mainnet-beta.solana.com"),
  cluster: "mainnet",
  jwt, // optional — pass an existing token, or log in (below)
});

The constructor takes:

| Option | Required | Description | | ------------------ | -------- | --------------------------------------------------------------------------------- | | apiUrl | yes | Base URL of the Mooncast API. | | jwt | no | An existing JWT. Your frontend can pass one it already holds. | | connection | for tx | A @solana/web3.js Connection. Required for transaction methods (Switchboard). | | cluster | no | "mainnet" (default) or "devnet" — selects the Switchboard queue. | | computeUnitPrice | no | Priority fee in micro-lamports (default 75_000). |

Authentication

Auth is a wallet-signature challenge that returns a JWT. Sign the returned message with the user's wallet, then log in. On success the token is stored on the client automatically.

const { message } = await client.auth.challenge(wallet.publicKey.toBase58());

const signature = await wallet.signMessage(new TextEncoder().encode(message));

const token = await client.auth.login({
  wallet: wallet.publicKey.toBase58(),
  message,
  signature: bs58.encode(signature),
});

If the frontend already has a token, skip this and pass jwt to the constructor (or client.setJwt(token)).

Reading data

const config = await client.read.config();
const user = await client.read.user(wallet);
const tokens = await client.read.tokens();
const player = await client.read.player(wallet);
const rounds = await client.read.rounds(wallet, { limit: 20, offset: 0 });
const round = await client.read.round(123);

Building transactions

Transaction methods return ready-to-sign VersionedTransactions. Have the connected wallet sign and send them.

Flip a coin

Randomness is created and committed for you. Because Switchboard requires the randomness account to be created first, then committed in the same transaction as your program instruction, coinflip() returns two transactions to send in order:

const { randomnessAccount, createTransaction, commitTransaction } = await client.tx.coinflip({
  amount: 1_000_000,
  choice: coinflip.CoinflipSide.Heads,
});

// 1) create the randomness account
await wallet.sendTransaction(createTransaction, connection);
// 2) commit + flip
await wallet.sendTransaction(commitTransaction, connection);

// keep `randomnessAccount` — you need it to settle

Settle a flip

Prepends the Switchboard reveal instruction:

const settleTx = await client.tx.settle({ randomnessAccount });
await wallet.sendTransaction(settleTx, connection);

Other transactions

await client.tx.initUser();
await client.tx.deposit(5_000_000);
await client.tx.swap(2_000_000);

All of these require the client to be authenticated (a JWT) — the wallet the transaction is built for comes from the token, not the request body.

Live WebSocket feed

Open a socket (JWT-authenticated) and subscribe to rooms. On connect you automatically receive your own wallet's events and the global feed. Events are pushed live — including your own flip outcomes as they settle.

const socket = client.ws().connect();

socket.on(coinflip.events.GAME_ROUND, (round) => {
  console.log("flip settled:", round.is_win, round.outcome);
});

socket.on(coinflip.events.PLAYER_STATE, (player) => {
  console.log("player state changed:", player);
});

// subscribe to any public room
socket.subscribe("global");

// listen to everything
socket.on(coinflip.events.ALL, (data, message) => {
  console.log(message.type, data);
});

socket.close();

Event types (coinflip.events): CONFIG, TOKEN_WHITELIST, USER, PLAYER_STATE, GAME_ROUND, TRANSACTION, and ALL ("*").

Scaling

Each API instance consumes every event from its own exclusive queue and forwards to its locally connected clients, so you can run the API behind a load balancer and horizontally scale the WebSocket layer with no shared state.

Environments

  • Browser: uses the global fetch and WebSocket. No extra setup.
  • Node.js (18+): fetch is built in. For WebSockets, set globalThis.WebSocket (e.g. from the ws package) before connecting.

API surface

import { coinflip } from "@hellomoon/camelot-sdk";

coinflip.MooncastSdk; // main entry point
coinflip.CoinflipSide; // Tails = 0, Heads = 1
coinflip.events; // event-type constants
coinflip.WsClient; // websocket client
coinflip.CoinflipApiError;
// plus response types: Config, User, TokenWhitelist, PlayerState, GameRound, Transaction

License

MIT