Ledger and audit log
What this is
Two optional modules for a registered game. The ledger holds the game’s own currency: accounts, movements that happen once, and a balance that cannot go below zero. The audit log holds the game’s staff actions in a chain that shows if an entry was changed. Both belong to one game. Nothing here moves between games, and nothing is real money.
Each module has a switch on Arena54’s side. While a switch is off, its calls answer 503 module_off. Tick Ledger or Audit log for your game in the dashboard either way, and create a secret test key for it.
Who may call
| Caller | Ledger | Audit log |
|---|---|---|
| Your server, with a secret key | Everything for its own game | Append, read, verify |
| Your page, with a publishable key and a player token | Read that player’s own account and rows | Nothing |
A page never writes, because anything a page could write, a player could write. So a game with no server cannot grant or spend currency yet. A secret key sent from a browser is refused with 403 secret_key_in_browser: keep it in an environment variable on your server, for example ARENA54_SECRET_KEY, and never commit it.
A test key writes to a test ledger and a test chain of its own. They never touch the live ones.
Accounts
const API = "https://developers.arena54.com/api/v1";
const headers = { Authorization: "Bearer " + process.env.ARENA54_SECRET_KEY };
const call = async (method, path, body) => (await fetch(API + path, { method, headers, body: body && JSON.stringify(body) })).json();
// One account per owner. Opening it again returns the same one.
const player = (await call("POST", "/ledger/accounts", { kind: "player", owner: playerId })).data;
const shop = (await call("POST", "/ledger/accounts", { kind: "treasury", owner: "shop" })).data;An account is a player, a treasury (the game’s own holdings) or a sink (where currency goes to be destroyed; it alone may go below zero). For a player, use the id from /play/me as the owner, and the page’s /ledger/me will find it.
Moving currency
// One account: makes or removes currency. Whole numbers only. `ref` is yours and makes it happen once.
await call("POST", "/ledger/movements", { account: player.id, delta: 100, kind: "daily-grant", ref: "grant-2026-10-12-" + playerId });
// → { id, balance_after: 100, replay: false }. Send it again and you get the same answer with replay: true.
// Several accounts: moves currency, makes none. All legs or none.
await call("POST", "/ledger/transfers", { ref: "order-8841", legs: [
{ account: player.id, delta: -40, kind: "buy" },
{ account: shop.id, delta: 40, kind: "buy" },
]});- Decide the amount on your server. Never take a delta from the page.
- A
refis 1 to 200 characters, akindis lowercase likedaily-grant. The same kind and ref again is a repeat, answered from the stored row whatever the repeat asked for. - A correction is a new movement with its own kind. There is no edit and no delete.
- Freeze an account with
POST /ledger/accounts/{id}/freezeand{ actor, reason };/unfreezeundoes it. Each writes an audit entry.
Swapping for another game’s currency
A player who plays two games can swap one game’s currency for the other’s. No real money is involved, and neither game’s supply changes: what the player pays goes into your game’s reserve, and what they receive comes out of the other game’s reserve. The exchange has its own switch on Arena54’s side; while it is off the call answers 503 module_off.
| Method | Path | Purpose |
|---|---|---|
| POST | /v1/ledger/exchange | Swap the player’s currency in this game for another game’s, at the rate both makers agreed. Needs the player’s token |
await fetch("https://developers.arena54.com/api/v1/ledger/exchange", {
method: "POST",
headers: { Authorization: "Bearer " + process.env.ARENA54_SECRET_KEY, "X-Arena54-Player": playerToken, "Content-Type": "application/json" },
body: JSON.stringify({ to: "other-game-id", amount: 100, ref: "swap-8841" }),
});
// → { swap, to, amount_in: 100, amount_out: 250, rate: 2.5, balance_after, currency_in, currency_out, moved: true, replay: false }- Both makers agree the route. In the dashboard you offer a rate (theirs for one of yours) and the most one swap may take. The other maker accepts. Change the rate and they must accept again.
- The reserve. Each game has a treasury account whose owner is
exchange. Open it withPOST /ledger/accountsand fund it like any treasury. A swap into your game pays out of yours; when it is empty the swap answers409 no_reserves. - The player is there. Send their token as
X-Arena54-Player. They must be connected to both games. - Whole units, rounded down. An amount too small to buy one unit answers
400 too_small. - All or nothing, once per
ref. Both ledgers move in one step. The same reference again answers the first result withreplay: true, at the rate it was made at. 409 cannot_exchangeis one answer for two reasons: the player holds nothing in your game, or does not play the other. You are not told which.- Each game’s ledger shows its own rows (kinds
exchange.outandexchange.in) and its audit log its own entry. Neither is given the other’s id for the player. - A test key works out the answer and moves nothing:
moved: false, test: true.
Reading
| Method | Path | Purpose |
|---|---|---|
| GET | /v1/ledger/accounts/{id} | Balance and whether it is frozen |
| GET | /v1/ledger/accounts/{id}/rows | Statement, newest first. limit up to 100; before = the last id you saw |
| GET | /v1/ledger/supply | What exists, and what was created and destroyed, by kind. balanced: true means they agree |
| GET | /v1/ledger/reconcile | Every account whose balance differs from its rows. whole: true means none |
| GET | /v1/ledger/totals | Count, in and out by kind and by day (Lagos), up to 90 days with ?days= |
| GET | /v1/ledger/me | From a page: the signed-in player’s balance |
| GET | /v1/ledger/me/rows | From a page: the signed-in player’s statement |
The audit log
await call("POST", "/audit", { actor: "mod-ada", action: "player.ban", target: playerId, reason: "cheating", details: { days: 7 } });
const recent = await call("GET", "/audit?action=player.ban&limit=20"); // also actor=, target=, before=
const check = await call("GET", "/audit/verify"); // { whole: true, first_bad_id: null }Each entry stores a hash of the one before it, so a changed or missing entry shows at /audit/verify. Arena54 adds the time. An action is lowercase like player.ban; details are 4,000 characters at most. There is no edit and no delete.
Refusals
| Code | Status | When |
|---|---|---|
| module_off | 503 | Arena54 has the module switched off |
| module_not_enabled | 403 | The module is not ticked for this game |
| secret_key_required | 403 | A publishable key asked for more than /ledger/me |
| secret_key_in_browser | 403 | A secret key arrived from a page |
| not_enough | 409 | The account does not hold enough. Nothing moved |
| frozen | 409 | The account is frozen. Nothing moved |
| id_conflict | 409 | That kind and ref were already used for a different account |
| no_account | 404 | This game has no account with that id |
| bad_amount | 400 | A delta that is not a whole number other than zero, or a missing kind or ref |
| unbalanced | 400 | A transfer whose deltas do not sum to zero |
| bad_request | 400 | A body that is not the shape asked for |
| limit | 429 | The day’s movements or entries for this game, on your plan, are used up. Nothing was written |
Limits
Movements a day and audit entries a day for a game come from your plan, with the usual calls a minute per key. See pricing.