One script, served at /__darehop/sdk.js. The older path /__darehop/sdk-v1.js is this same file.
Store pages declare SDK 1.0. Calls return promises, except loading, gameplay markers, and analytics, which are fire and forget.
Messages travel over postMessage on the darehop-sdk channel. The portal only answers your game’s own frame and origin, and every call times out after 30 seconds (a call that waits for the player has no timeout while they decide).
Minimal index.html
Put it at the root of the zip (or inside one top folder).
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>My game</title>
<!-- Served by DareHop on your game's origin. Don't bundle or host it yourself. -->
<script src="/__darehop/sdk.js"></script>
</head>
<body>
<canvas id="game"></canvas>
<script src="game.js"></script>
</body>
</html>
A round, start to finish
game.js — sessions, pause, mute and saves.
async function start() {
DareHop.game.loading(0.2);
const info = await DareHop.init(); // { player, settings, environment, ... }
game.setMuted(info.settings.muted);
DareHop.game.loading(1);
DareHop.on("pause", () => game.pause()); // tab hidden, or a portal dialog
DareHop.on("resume", () => game.resume());
DareHop.on("settings", (s) => game.setMuted(s.muted));
}
start();
async function playRound() {
const { sessionId } = await DareHop.game.start();
DareHop.game.gameplayStart();
const score = await game.run();
DareHop.game.gameplayStop();
await DareHop.game.end(sessionId, { score }); // records the score; a round pays nothing by itself
}
async function saveProgress(update) { // cloud saves with conflict detection
for (let i = 0; i < 3; i++) {
const cur = await DareHop.storage.get("progress"); // { value, revision }
try { return await DareHop.storage.set("progress", update(cur.value), { expectedRevision: cur.revision }); }
catch (e) { if (e.code !== "save_conflict") throw e; } // another device wrote first: read, merge, retry
}
}Test without DareHop
Open your index.html on localhost, 127.0.0.1 or as a file: page and the SDK answers every call itself: saves go to localStorage, rounds follow the real rules and award nothing, Coins are fake, and events are printed to the console. Add ?darehop_debug=1 to use it on any address, or ?darehop_player=signed_in to pretend the player is signed in.
DareHop.debug.emit("pause") simulates the portal’s events. Debug mode never turns on inside DareHop. To see the game inside DareHop before release, open its preview from a version page.
Errors
A failed call rejects with a DareHopError that has code, retryable and details. Branch on the code:
Automatic checks on every upload
1
Archive structure
index.html at the root of the zip (or of one top folder).
2
Size
Up to 50 MB unpacked, 1,500 files.
3
DareHop SDK
index.html loads /__darehop/sdk.js.
4
Outside network requests
No http(s) URLs to other hosts. Ads and saves go through the SDK.
5
Forbidden code
No eval, new Function, document.cookie, or access to window.top/parent.
6
Manifest
Store page fields are filled and the SDK version matches the build.
A failed check blocks review; warnings are shown to the reviewer. Builds are limited to 1,500 files.
Coins and Coin packages
Your game can have its own Coins. Players buy Coins with DareHop Credits, or earn them in your game. You never see the player’s Credits.
Value moves one way: money buys Credits, Credits buy your Coins, Coins buy items in your game. Nothing converts back.
Coins are sold in packages. You set each package: a price in Credits for a number of Coins, for example 10 Credits for 1,000 Coins. Players cannot buy single Coins or pick an amount, and your game sends only a package id. DareHop shows the purchase dialog with the real price. Money from the Credits spent on your Coin packages is shared 50:50 between you and DareHop.
Earning and spending Coins happens in your game. DareHop keeps one number per player and game: the Coin balance. It does not record each reward or item. Keep a running change in your game, plus for Coins the player earned and minus for Coins spent, and send it with your next save (storage.set with coinsDelta), at the latest when the round ends. DareHop adds it to the balance in the same step as the save; the balance never goes below 0. Send each change once: save with expectedRevision, so a repeated request changes nothing. There are no reward tables, and rewards.claim is gone.
const { packages } = await DareHop.economy.getPackages(); // [{ id, title, credits, coins }]
label(packages[0].title + ": " + packages[0].coins + " Coins");
try {
// DareHop opens its own dialog and waits for the player.
const r = await DareHop.economy.buyPackage(packages[0].id); // { coins, coinsTotal, ... }
setCoins(r.coinsTotal);
} catch (e) {
if (e.code !== "cancelled") showError(e.code); // insufficient_credits, package_not_found, ...
}
// Coins the player earned or spent in your game: keep a running change (plus earned, minus spent)
// and send it with your next save. DareHop adds it to the balance and answers with the Coins it now holds.
change += 25; // cleared a level
change -= itemPrice; // bought an item
const saved = await DareHop.storage.set("progress", progress, { expectedRevision, coinsDelta: change });
change = 0;
setCoins(saved.coins);These calls need a grant from DareHop and a signed-in player: until DareHop turns them on for your game they fail with capability_denied or not_supported. Try them in debug mode with ?darehop_player=signed_in, which gives fake Coins.