@invonetwork/phaser
v1.0.0
Published
INVO game economy for Phaser 4: wallet, premium currency via INVO hosted checkout, item shop, soft-currency earnings and loyalty events, with a drop-in UI over your game canvas.
Maintainers
Readme
@invonetwork/phaser
INVO's game economy for Phaser 4: a wallet, premium currency sold through INVO's hosted checkout, an item shop, earned (soft) currency, and loyalty events, with a polished drop-in UI over your game canvas.
This is a thin adapter. Every economy rule lives in @invonetwork/web-sdk (3.27+) and is inherited here, never copied:
- Balances come from your server, which asks INVO. The browser never decides a balance.
- Premium purchases are credited exactly once, from INVO's signed webhook.
- Spending premium currency splits the sale 90% to you and 10% to INVO automatically.
Install
npm install @invonetwork/phaser @invonetwork/web-sdk phaser1. Server (Node)
Your game server holds the INVO secrets and the ledger. Mount the routes once:
import { createServer } from "node:http";
import { invoGameServerFromEnv, createFileGameStore, toNodeListener } from "@invonetwork/web-sdk/game-server";
import { economy } from "./economy"; // your shop: currencies, packs and items
const { server } = invoGameServerFromEnv({
economy,
env: process.env, // INVO_GAME_SECRET, INVO_WEBHOOK_SECRET, INVO_ENV=sandbox|production
store: createFileGameStore({ file: ".data/invo-ledger.json" }),
});
createServer(toNodeListener(server, serveYourGame)).listen(3000);Without the secrets the server still runs. The INVO routes answer 503 INVO_SETUP_REQUIRED, and the UI shows the developer a setup guide that notices when the keys arrive.
Set the INVO console's webhook URL to https://<your-game>/api/invo/webhook.
2. Game (browser)
import Phaser from "phaser";
import { installInvo, getInvo, InvoEvents, InvoBalanceText } from "@invonetwork/phaser";
const game = new Phaser.Game(config);
installInvo(game); // mounts the INVO UI and talks to /api/invo
// In any scene:
const { economy, ui } = getInvo(this);
economy.earn(5, "crystal mined"); // batched and rate-limited by the server
if (economy.owns("golden_skin")) applySkin();
this.game.events.on(InvoEvents.ITEM, (p) => applyItem(p.itemId));
ui?.openShop(); // or let players use the HUD's Shop button
this.add.existing(new InvoBalanceText(this, 16, 16, "soft"));API
| Export | What it does |
|---|---|
| installInvo(game, options?) | Mounts the UI over the canvas, pauses Phaser input while an INVO dialog is open, re-emits economy events on game.events. Returns { economy, ui, modalOpen, ready, destroy }. |
| getInvo(scene) | The handle from any scene. |
| InvoEvents | WALLET, SESSION, ITEM, PURCHASE, ERROR, MODAL, SETUP event names on game.events. |
| InvoBalanceText | A Phaser.GameObjects.Text that always shows a live balance. |
| InvoGameEconomy, mountInvoUI, types | Re-exported from @invonetwork/web-sdk/game. |
Options: economy (an instance or its options), ui (UI kit options or false to draw your own), container, pauseInputWhileModal (default true).
Starter template
A complete, forkable Phaser 4 + TypeScript starter (Replit-ready) wires all of this up: invo-game-templates.
For AI agents and step-by-step wiring, see INTEGRATION.md. Full docs: https://docs.invo.network
