Tallér: the coin system

High-level architecture for 501 · 25 November 2026 · not yet built

501 will sell a virtual coin, Tallér, as consumable in-app purchases. A player gets it by buying a pack, as a gift or by winning, and spends it where the game asks for it. This first project is the system underneath: hold a balance, add to it, take from it, list what happened, with a store screen whose purchase is a stand-in until a payment provider is chosen.

The idea

One balance

One number per account, whatever the source. Never below zero.

A ledger that adds up

Every change is a line that is never edited. Ledger and balance always agree, and one query proves it.

Counts once

A retry, a double tap or a repeated webhook changes nothing the second time.

Packs are data

The server says which packs exist and what they give. No app release to change one.

The provider is a plug

A stand-in now, a real provider later, with nothing around it changing.

The app never guesses

The balance shown is always one the server answered.

Scope

NowLater
  • Balance, ledger, packs, purchases
  • Add, remove, undo
  • Store screen: balance, packs, history
  • Stand-in purchase, development only
  • User groups; admins give and take their own coins from the debug menu
  • Real payment provider, refunds
  • Account recovery and deletion
  • Rooms with an entry fee and a pot: moving coins between players
  • Daily and weekly gifts, rewarded ads
  • Admin screen

How it fits together

App
Screensbalance chip, store, “not enough” dialog
Coin databalance, packs, history, purchases waiting to be confirmed
Purchase servicestand-in now, provider SDK later
⇄
API
Coin routespacks, history, confirm a purchase
Coin servicethe only code that touches a balance
Purchase providerstand-in now, real provider later
→
Database
Balanceon the user
Ledgerevery change, one line each
Packswhat is sold
Purchaseswhat was bought

Dashed boxes are the two places a real provider plugs in.

Tables

users one new column

coin_balance
the number the player sees; the database refuses a value below zero. Only the coin service writes it

coin_entries the ledger; never edited or deleted

id
rising number; history pages by it
user_id
→ users
type
purchase, reversal, adjustment now; gift, ad reward, stake, payout later
amount
+ in, − out
balance_after
the balance once this line is written
idempotency_key
unique per player and type: the same write counts once
ref_type, ref_id
what it was for: a purchase now, a room or a game later
group_id
lines written together share one (a pot)
reverses_entry_id
→ coin_entries; an entry is undone once
context
internal details; never sent to the app as stored
created_at

coin_packs switched off, never deleted

id
store_product_id
unique; the same id in both stores. A key only: nothing is read out of it
coins
the whole sum credited
bonus_coins
how much of it is shown as “on top”
tag
none, popular, best value
art_tier
which picture
sort_order
place in the row
is_active
listed in the store or not

coin_purchases one per store transaction

id
user_id
→ users
pack_id
→ coin_packs
store
Apple, Google, or the stand-in
environment
production or sandbox, so a test purchase cannot mint real coins
store_transaction_id
unique per store: one transaction credits one account, once
coins_credited
as it was then, whatever the pack says now
status
credited, refunded; pending and revoked when a provider needs them
entry_id
→ coin_entries, the line that credited it
price, currency, country
as the provider reports them; cannot be filled in later
created_at, refunded_at

user_groups who may use admin routes

user_id
→ users
group_name
admin today; more groups later
created_at

A purchase row and its ledger line are written in one transaction: both are there, or neither.

A route names the groups it allows, and membership is read from the database on every request, so removing someone works at once. Nothing in the API makes an admin: that is done by hand, where the database is.

Changing a balance

One service. Each operation is a single database transaction that locks the player's balance, updates it and writes its ledger line together, and it can join a larger transaction, so a credit lands with its purchase and a stake will land with its seat.

Credit

Add coins to a player.

Debit

Take coins. Too few: refused, nothing changes.

Reverse

Undo one line. A store refund. Stops at zero and records what could not be taken back.

Transfer later

Several players at once, all or none. Built with the rooms that need it; the tables already have room for it.

Every ledger line says what it was, carries a unique key so it counts once, and stores the balance after it. A write sent again is answered “already done” before anything else is checked.

A purchase

The app confirms, the provider's webhook is the backup. Both use the same key, so whichever arrives first credits and the other changes nothing.

Changing packs

ChangeStoresOur serverApp release
Coins, bonus, tag, picture, ordernothingupdate the packno
Priceedit in the consolenothingno
Add a packcreate the product in both; Apple reviews itadd the packno (the very first product ships with an app version)
Retire a packnothingswitch it off, never deleteno

In the app

The chip

Coin and balance, top right in the lobby. A tap opens the store.

The store

Packs in a row that scrolls sideways, dearest first, and the history of what came in and went out.

Not enough later

A dialog saying what is needed and what the player has; it leads to the store. Built with the first feature that charges.

The balance is only ever set from a server answer, and never from an older one. The store stays out of release builds until a real provider is in place.

Before real money

Open questions

  1. Does a new player start with some Tallér, and how much? Not needed to build this; can be added later.
  2. Which payment provider (Adapty is likely).
  3. Real pack amounts and prices. Placeholders until then; changing them is data, not code.

Roadmap

  1. Coins underneathLedger, packs, stand-in purchase, store screen.
  2. Real moneyAccount recovery, then the provider.
  3. Free coinsGifts and rewarded ads.
  4. Rooms with a feeMoving coins between players: entry, pot, games without a winner.