Quick start

The InstFun platform gives H5 games hosted on instfun.games access to accounts, cloud saves, leaderboards, wallets, ads and analytics. The SDK offers two runtime modes and your game code does not need to tell them apart: with a backend, data is server-authoritative; without one, it falls back to browser storage.

Current SDK version: 1.2.0.

Include the SDK

Games hosted by the platform can load the single-file CDN bundle (same origin, no build step, global window.Instfun):

<script src="/sdk/v1/instfun.js"></script>

Third-party source integrations built on the instfun platform can use the same global object; type definitions are provided separately.

Initialize

const sdk = await Instfun.init({ gameId: "my-game", gameVersion: "0.1.0" });

gameId must match the gameId in the game-info.json inside your published package; in remote mode it also determines account data and leaderboard ownership.

Read the account

const user = await sdk.account.getCurrentUser();

A guest account is created automatically; binding an email lets players recover it on another device (see the Integration guide).

Cloud saves and records

const progress = await sdk.game.loadProgress();
await sdk.game.start({ level: progress?.data.level ?? 1 });
await sdk.game.saveProgress({ level: 4, bestScore: 8320 }, { merge: true });
await sdk.game.finish({ result: "complete", score: 8320, submitScore: true });

Saves are local-first in both modes; in remote mode an offline result carries pendingSync: true and is reconciled by sdk.sync().

Leaderboard

const board = await sdk.leaderboard.get({ boardId: "global" });

Local mode returns the on-device best (localOnly: true); remote mode returns the global board (scope: "global") and falls back to the local board when offline.

Analytics and ads

sdk.analytics.track("level_complete", { level: 4 });
const ad = await sdk.ads.showRewarded({ placement: "DOUBLE_REWARD" });

track never throws; a rewarded ad grants its reward through the SDK idempotently after a full view — do not add currency yourself.

Reconcile offline data

await sdk.sync();

sync() uploads the analytics queue and retries offline saves, records and leaderboard submissions. Call it after startup, when the page returns to the foreground, and when the network recovers.

Next steps

  • Runtime modes, accounts, email binding, save sync and offline behavior: see the Integration guide
  • Every method and type: see the API reference
  • Packaging and submission: see Publishing