Beetles Docs

Gaming Economy & Virtual Points

High-scale virtual currency management with sinks, faucets, and item stores.

Gaming Economy & Virtual Points

Virtual worlds and games require high-throughput ledgers to manage "Faucets" (how money enters the game) and "Sinks" (how money is removed to control inflation). Beetles' ability to handle millions of transfers per second makes it ideal for gaming backends.

Architecture

In a gaming economy, the @world account represents the game's central bank or "Minter". Every credit comes from this infinite supply, and every "Burn" returns to it or goes to a specialized "Sink" account.

Core Gameplay Loops

Granting Rewards (The Faucet)

When a player completes a quest, the game engine "mints" new currency by debiting the @world account.

Reward Transfer
curl -X POST http://localhost:8080/v1/transfers 
  -d '{
    "debit_account_id": "WORLD_GOLD_ID",
    "credit_account_id": "PLAYER_ACC_ID",
    "amount": 500,
    "code": 50, # Code: "Quest Reward"
    "metadata": { "quest_id": "dragon_slayer_01" }
  }'

Purchasing Items (The Sink)

To prevent inflation, games use "Sinks" where currency is removed from circulation. Buying a cosmetic item is a transfer from the player to a "Sink" account.

Item Purchase
curl -X POST http://localhost:8080/v1/transfers 
  -d '{
    "debit_account_id": "PLAYER_ACC_ID",
    "credit_account_id": "GOLD_SINK_ID",
    "amount": 2500,
    "code": 60 # Code: "Store Purchase"
  }'

Advanced Gameplay Mechanics

1. Atomic Player-to-Player Trading (Escrow)

To prevent "scams", use Beetles' Two-Phase Commit (2PC) or Linked Transfers. When Player A trades Gold for an Item (represented as a unit in an Item Ledger) from Player B:

Atomic Swap
curl -X POST http://localhost:8080/v1/transfers \
  -d '{
    "transfers": [
      { "debit_account_id": "PA_GOLD", "credit_account_id": "PB_GOLD", "amount": 1000, "linked": true },
      { "debit_account_id": "PB_ITEM", "credit_account_id": "PA_ITEM", "amount": 1, "linked": false }
    ]
  }'

2. Loot Boxes & Probabilistic Minting

When a player buys a loot box, the engine:

  1. Debits the player (Sinks the currency).
  2. Mints a random item (Credits the player from @world). By linking these two, you ensure the player never pays without receiving an item, or vice versa.

Anti-Fraud & Limits

Beetles' engine-level constraints allow you to set:

  • Maximum Supply: Prevent the @world account from issuing more than a total amount by checking the ledger's total volume.
  • Negative Balances: Player accounts should never have flags: { "debit_must_not_exceed_credits": true } set, ensuring they can't spend money they don't have.

In gaming, eventual consistency is your enemy. Using Beetles ensures that if a player spends their gold in the store, it's immediately deducted, preventing "double-spending" bugs even under heavy server load.

On this page