Client SDK

@huddle/sdk runs in your Activity, with a publishable key. Every call acts for the player whose Discord token comes with it, and only for them, so the key is safe to ship.

import { Huddle } from "@huddle/sdk";

const huddle = new Huddle({
  publishableKey: "hdl_pub_…",
  accessToken: () => getDiscordToken(),   // a string, or a function called before each request
  discordSdk,                             // to open the linking page; window.open otherwise
  // baseUrl: "/.proxy/huddle" inside Discord (default); your API URL outside it
});
Method Returns
me() { user: { id, username, displayName, avatarUrl }, wallet: { address, linkedAt } | null, held, cluster }
link({ signal?, pollMs? }) { address } once the player linked in their browser. Rejects with link_expired after 15 minutes
claimCode(code) { address, linkedAt }: links the wallet behind a code from the linking page
unlink() { address | null }
balance() { address, lamports, sol } of the player's wallet
tokens(mint?) { address, tokens: [{ mint, amount, decimals, uiAmount }] }
watch(onChange, { intervalMs? }) calls back when the wallet or the held list changes; returns stop()
setAccessToken(token) updates the token

Errors are HuddleError with status, code and message (see the API reference). Network errors, 5xx and retryable 429s are retried twice.

NextServer SDK