Preview. Stack v4.0 has not been released, and what is documented here can still change before it does. The current release is v3.2, which covers this as Assets.Go to v3.2
Ledger

Assets, Amounts, Balances, and Volumes

Encode monetary values as integers and interpret account and aggregate volumes.

Ledger records amounts as unsigned integers. The asset identifier carries the unit and, when needed, its decimal precision. This keeps monetary arithmetic deterministic and avoids floating-point rounding inside the ledger.

To run these behaviors against a live ledger, follow Amounts, balances, and volumes in the hands-on walkthrough. It sets up a disposable ledger once and reproduces every result shown below.

For the complete route contracts, see Create Transactions with Postings and Revert Transactions.

Define one asset identifier#

An asset uses an uppercase base followed by an optional decimal precision:

EUR/2
USD/2
TOKEN/18
POINTS

The base must match [A-Z][A-Z0-9]{0,16}. The optional precision is an integer from 1 through 255 without a leading zero. USD, USD/2, and USD/4 are distinct stored assets.

Choose one representation for each business asset and use it in every writer. Inconsistent precision creates separate balances that only look related to a human reader.

Convert display values to integers#

The precision states how many decimal places your application applies when it displays an amount:

Display valueAssetLedger amount
EUR 12.34EUR/21234
USD 0.01USD/21
1 tokenTOKEN/181000000000000000000
25 pointsPOINTS25

Use the same rule in both directions:

ledger amount = display amount * 10^precision
display amount = ledger amount / 10^precision

Perform this conversion with decimal or integer arithmetic. Do not pass an IEEE-754 floating-point result into a transaction request.

Posting amounts and cumulative volumes can use the full unsigned 256-bit range. JavaScript Number cannot represent all of these integers. Use BigInt, a decimal library, or a serializer that preserves the original integer text.

The HTTP transaction request represents a posting amount as a JSON integer:

json
{
  "postings": [
    {
      "source": "world",
      "destination": "customers:alice:wallets:main",
      "asset": "EUR/2",
      "amount": 1234
    }
  ]
}

Ledger rejects malformed asset identifiers and any operation that makes a cumulative input or output volume exceed 2^256 - 1.

Read input, output, and balance#

For each (account, asset, color) bucket, Ledger maintains two cumulative volumes:

  • input is the total received by the account;
  • output is the total sent by the account;
  • balance is input - output.

Consider three movements in EUR/2:

  1. world sends 10000 to Alice;
  2. Alice sends 2500 to a merchant;
  3. the merchant sends 500 to platform fees.
AccountInputOutputBalance
customers:alice:wallets:main1000025007500
merchants:acme:earnings25005002000
platform:fees5000500

Reading an account returns those volumes as decimal strings:

json
{
  "data": {
    "address": "customers:alice:wallets:main",
    "volumes": [
      {
        "asset": "EUR/2",
        "color": "",
        "volumes": {
          "input": "10000",
          "output": "2500",
          "balance": "7500"
        }
      }
    ]
  }
}

Parse these response values as arbitrary-precision integers. A balance can be negative when a transaction explicitly permits an overdraft, even though input and output remain unsigned.

Volumes preserve movement history#

Input and output answer different questions from balance. Two accounts can have the same balance but very different activity.

A reversal records new postings in the opposite direction. It does not subtract from the original cumulative volumes. After a transfer and its reversal, the balance can return to its previous value while both input and output have increased.

For NORMAL account types, these volumes remain available after the balance returns to zero. An EPHEMERAL type can remove a zero-balance volume row, and a TRANSIENT type does not store a volume row after the transaction. Do not use either mode when reports require lifetime input and output from direct account reads.

Use:

  • balance for the current net position;
  • input and output for cumulative flow and turnover;
  • transactions and logs for the exact history that produced those values.

Aggregate volumes across accounts#

Use the GET /v3/{ledger}/volumes endpoint when you need totals for a set of accounts. It returns decimal-string input, output, and balance values, and supports:

ParameterPurpose
filterSelect the accounts to total. address ^= "customers:" matches an address prefix. This is the only account selector the route accepts.
groupByPrefixesReturn separate totals for a comma-separated set of prefixes.
useMaxPrecision=trueRescale assets with the same base to the highest precision found in the result.
collapseColors=trueSum color buckets for reporting. Stored balances remain separate.

Ledger 3.0 removed the prefix parameter this route used to accept. An unrecognized parameter is ignored rather than rejected, so sending prefix= still returns 200 — with a total across every account in the ledger, world included, that looks exactly like a scoped one. The response carries no addresses, so nothing in it reveals the difference.

useMaxPrecision is a reporting aid, not a correction for inconsistent writers. Standardize the asset at write time and use precision merging only when you deliberately need a combined view.

Verify an amount integration#

Run the following checks before production traffic:

  1. convert a display amount to an integer and back without loss;
  2. send the smallest supported unit, such as 1 for EUR/2;
  3. read the destination and confirm its input and balance increased by exactly that integer;
  4. move part of the balance out and confirm only output increased;
  5. revert the movement and confirm the balance recovers while cumulative volumes continue to record activity;
  6. test values above your language's native safe-integer range.

Common failure modes#

SymptomCauseCorrection
EUR 12.34 is recorded as 12 or 1233Floating-point conversion or wrong scaleConvert with decimal arithmetic to 1234 EUR/2.
One currency appears in several balance rowsWriters use USD, USD/2, and USD/4 inconsistentlyPublish one official asset identifier.
A client rounds large amountsIt parses JSON values through a fixed-width or floating-point numberPreserve arbitrary-precision integers end to end.
Balance returns to zero but activity totals do notA reversal added compensating postingsUse balance for net position and volumes for cumulative flow.
Prefix aggregation includes customers:10 when requesting customers:1Prefix matching is byte-basedInclude the intended segment delimiter, such as customers:1:.

Use colors only when two balances with the same asset must remain isolated. Do not encode provenance by creating ad hoc asset names.