This repository showcases how to integrate the Stellar SDK within the Beamable ecosystem for an HTML5 game built on Next.js. It covers Beam bootstrap, custodial and external wallet attachment, content/inventory sync, commerce, and the Tower Destroyer gameplay loop.
- 🎯 Arcade slingshot loop: fire balls to topple towers, earn score, and clear stages.
- 🗺️ Progression: advance through campaign stages, repeat loops for higher difficulty, and unlock mechanics as you go.
- 🧰 Loadouts: collect different ball types (normal, multishot, fire, laser) with varying speed/power; a default ball is granted automatically.
- 💰 Economy: earn coins from wins, sync them to Beam/Stellar, and purchase ball listings from the in-game shop.
- ⏳ Minting delay: Stellar mints settle on a fixed cadence; after purchases/grants/coin sync it can take ~10–15 seconds before inventory reflects the change. The UI keeps the loading/refresh state up during this window; if something looks “stuck”, wait a moment and then tap Refresh in the shop.
- 🛡️ Identity flow: set an alias, auto-attach a custodial wallet, and optionally attach an external Stellar wallet via WalletConnect-style popups.
- 🚀
npm install - 🗂️ Add
.beamable/connection-configuration.jsonwith your CID/PID (see below). - 🧪 Create
.env.localas needed and runnpm run dev.
Primary source of truth: .beamable/connection-configuration.json (consumed via app/api/beam-config/route.ts):
{ "cid": "your-cid", "pid": "your-pid", "host": "https://api.your-cluster.com" }Environment overrides:
NEXT_PUBLIC_BEAM_ENV/BEAM_ENV: environment key (prod,stg,dev, or custom).NEXT_PUBLIC_BEAM_HOST/BEAM_HOST: override API host without editing.beamable.NEXT_PUBLIC_BEAM_CID/NEXT_PUBLIC_BEAM_PID: fallback if the file is missing.NEXT_PUBLIC_STORE_CONTENT_ID: store content id for commerce (defaultstores.Store_Nf).NEXT_PUBLIC_DEBUG_LOGS=true: enable verbose client logging.
Example .env.local:
NEXT_PUBLIC_BEAM_ENV=stg
NEXT_PUBLIC_BEAM_HOST=https://api.stg.beamable.com
NEXT_PUBLIC_STORE_CONTENT_ID=stores.Store_Nf
NEXT_PUBLIC_DEBUG_LOGS=true
- 🛠️
npm run dev: Start Next.js in development. - 📦
npm run build: Production build. - 🚦
npm run start: Serve the built app. - 🔍
npm run lint: Lint viascripts/run-lint.cjs. - ✅
npm run test: Vitest suites (physics, content caching, commerce caching).
- ✨ Beam bootstrap (
lib/beam.ts): Resolves config from.beamable, env vars, orwindow.__BEAM__; registers custom environments when a host override is present; initializes Beam withclientServicesand the generatedStellarFederationClient; auto-logs guests to ensure tokens. - ⭐ Stellar federation (
lib/beam/player.ts,beamable/clients/StellarFederationClient.ts): Custodial identity attach, external identity attach/login, WalletConnect URL builder, and microservice endpoints (addItem,purchaseBall,updateCurrency, plus the external wallet callback endpointsexternalAddress/externalSignature). - 🔔 Notifications (
lib/notifications.ts): Raw websocket subscriptions forexternal-auth-addressandexternal-auth-signature, with payload normalization for the wallet handshake. - 📦 Content / Inventory / Commerce (
lib/beamContent.ts,lib/beamInventory.ts,lib/commerceManager.ts): Content fetch and caching, inventory helpers over the generated OpenAPI calls, store + listing resolution with cache keys by store/manifest. - 🏗️ Game loop and UX (
components/Game/*,hooks/*): Canvas physics and state, campaign progression, ball loadouts, currency sync, shop purchases, identity bootstrap, wallet pop-up orchestration, and overlays for player info and campaign flow.
- Location:
BeamableServices/services/StellarFederation. - Identity namespaces: custodial
StellarWeb3Identity, externalStellarWeb3ExternalIdentity(StellarFederationCommon/StellarFederationCommon.cs). - Startup (
Program.cs): preload common assembly, prepare microservice, register shutdown hook, and start the hosted background worker. - DI:
ServiceRegistration.AddFeaturesauto-registersIServicetypes;Endpoints/ServiceRegistrationwires auth/inventory endpoints. - Initialization (
StellarFederation.InitializeServices): set up Mongo extensions, validate realm config, create realm wallet, initialize Soroban contracts, and start the scheduler (non-DEBUG builds). - Client-callables:
StellarConfiguration,CreateAccount,GetAccount, inventory helpers (UpdateCurrency,AddItem,RemoveItem,UpdateItems), plus adminJobs/BlockProcessor. - External callbacks:
ExternalAddressandExternalSignaturefeed wallet-connect bridge responses and trigger player notifications. - Microservice readme
- 📌 Keep
.beamable/connection-configuration.jsonaligned with your target cluster; prefer env overrides for quick host/env switches. - 🪟 If a popup blocker prevents wallet attach, use the logged URL or enable popups and retry.
- ✅ After SDK updates, re-run
npm run testand sanity-check wallet attach and commerce flows end-to-end.