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

CallerLedgerAudit log
Your server, with a secret keyEverything for its own gameAppend, read, verify
Your page, with a publishable key and a player tokenRead that player’s own account and rowsNothing

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

Your server
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

Your server
// 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 ref is 1 to 200 characters, a kind is lowercase like daily-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}/freeze and { actor, reason }; /unfreeze undoes 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.

MethodPathPurpose
POST/v1/ledger/exchangeSwap the player’s currency in this game for another game’s, at the rate both makers agreed. Needs the player’s token
Your server
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 with POST /ledger/accounts and fund it like any treasury. A swap into your game pays out of yours; when it is empty the swap answers 409 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 with replay: true, at the rate it was made at.
  • 409 cannot_exchange is 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.out and exchange.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

MethodPathPurpose
GET/v1/ledger/accounts/{id}Balance and whether it is frozen
GET/v1/ledger/accounts/{id}/rowsStatement, newest first. limit up to 100; before = the last id you saw
GET/v1/ledger/supplyWhat exists, and what was created and destroyed, by kind. balanced: true means they agree
GET/v1/ledger/reconcileEvery account whose balance differs from its rows. whole: true means none
GET/v1/ledger/totalsCount, in and out by kind and by day (Lagos), up to 90 days with ?days=
GET/v1/ledger/meFrom a page: the signed-in player’s balance
GET/v1/ledger/me/rowsFrom a page: the signed-in player’s statement

The audit log

Your server
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

CodeStatusWhen
module_off503Arena54 has the module switched off
module_not_enabled403The module is not ticked for this game
secret_key_required403A publishable key asked for more than /ledger/me
secret_key_in_browser403A secret key arrived from a page
not_enough409The account does not hold enough. Nothing moved
frozen409The account is frozen. Nothing moved
id_conflict409That kind and ref were already used for a different account
no_account404This game has no account with that id
bad_amount400A delta that is not a whole number other than zero, or a missing kind or ref
unbalanced400A transfer whose deltas do not sum to zero
bad_request400A body that is not the shape asked for
limit429The 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.