The Formance Ledger represents financial activity using two primitives: postings and transactions. Postings are the basic unit of movement; transactions are timestamped containers that group one or more postings together.
A committed transaction's financial content is immutable: its postings, amounts, assets, and timestamp can never change. To correct an error, see Reverting Transactions. Metadata is the exception — it can be added or removed at any time after commit, as described in Metadata below.
Postings#
A posting records the movement of an amount of an asset from a source account to a destination account.
Each posting has exactly one source and one destination. The Formance Ledger records the full history of postings; account balances are derived from that history rather than stored directly.
The asset field must match the ledger's asset pattern — an uppercase identifier, optionally with an _SUFFIX and an optional /precision — but beyond that shape the ledger attaches no meaning to it: there is no currency registry. By convention the name follows the ISO 4217 three-letter currency code (e.g. USD, EUR, GBP), suffixed with a precision indicator where the asset has decimals (USD/2 means amounts are expressed in cents). Custom asset names like COIN or REWARD_POINT are equally valid. See Assets for the exact pattern.
Transactions#
A transaction is a timestamped, permanently recorded grouping of one or more postings. For example, Alice trading coins for gems at a teller involves two postings in one transaction:
Atomicity#
Transactions are atomic: all of their postings are applied together, or none are. There is no intermediate state in which some postings have been committed and others have not.
The diagram above shows a customer payment split between a merchant and the platform. If the posting to platform:fees fails, atomicity means the posting to merchant:account is not applied either: the customer is not charged and the merchant receives nothing. There is no intermediate state where the merchant was paid but the platform was not.
Single source and destination postings#
Every posting in the Formance Ledger has exactly one source and one destination. When a split or fan-out is needed, use a transient intermediary account: funds move into it in one posting and out to each destination in separate postings, all within the same atomic transaction:
order:hold is the transient intermediary. It receives the full amount in the first posting and distributes it in the three that follow. All four postings commit atomically: either the full split happens, or nothing does.
The split logic ("5% to fees, 5% to the rider, the rest to the merchant") belongs in Numscript, which compiles your intent into unambiguous single-destination postings automatically.
Numscript runs on the machine interpreter by default. Experimental language features require the new interpreter — set runtime: experimental-interpreter on the transaction request. See Selecting an Interpreter.
Why not a single posting with multiple destinations?#
An alternative design would allow one posting to fan out to multiple destinations directly:
This is mathematically valid, but consider the questions you need a ledger to answer. Looking at alice's account: how much did alice pay in this transaction? Looking at the fees account: how much of this transaction went to fees? With a multi-destination posting, neither question has a clean answer; the amount field on the posting is ambiguous, and reconstructing per-destination flows requires parsing the posting's structure rather than reading a single number.
With single-destination postings, every question resolves to one posting with one unambiguous amount: alice moved exactly 2000 USD/2 to order:hold, and platform:fees received exactly 100 USD/2.
Volumes and Balances#
When a transaction commits, the ledger records the running totals (called volumes) on every account involved. The Ledger distinguishes between volumes and balances:
| Concept | Description |
|---|---|
| Volumes | The total input and output amounts processed for an account. Stored as unsigned integers, always non-negative. |
| Balances | The available amount in an account. Can be positive, negative, or zero. |
The ledger does not store balances directly. Instead, it records cumulative volumes. Balances are derived by subtracting output from input.
Terminology across the API#
The Formance Ledger uses different terms depending on context:
| Concept | Account component | API (postings) | API (volumes) |
|---|---|---|---|
| Value arriving in an account | Destination component | destination field | input field |
| Value leaving an account | Source component | source field | output field |
Postings (source/destination fields) describe movement between accounts. Volumes (input/output in preCommitVolumes and postCommitVolumes) are the running totals on each account before and after the transaction commits.
Metadata#
Transactions support metadata: key-value pairs you can attach at creation time or update later.
Setting transaction metadata#
Use set_tx_meta() in Numscript to attach metadata to a transaction at creation time:
Setting account metadata in a transaction#
Use set_account_meta() in Numscript to set or update account metadata as part of a transaction:
For managing account metadata outside of transactions, see Accounts.