Ledger

Double-entry Bookkeeping

Understand double-entry bookkeeping and how Ledger balances transfers between accounts.

Every transaction in Formance must balance: assets leaving one account must arrive in another. This is the principle of double-entry bookkeeping. Assets are never created or destroyed inside the ledger; they only move.

What it's for#

Double-entry is what makes the ledger trustworthy. It enforces conservation of assets at the database level, so any discrepancy between what entered the system and what accounts hold is structurally impossible, not a convention your code tries to maintain.

The three rules#

1. Transactions must balance#

Within a single transaction, the total amount added to source components must equal the total amount added to destination components. No assets are created or destroyed. In a multi-asset ledger this holds independently for each asset — USD/2 sources must balance USD/2 destinations, EUR/2 sources must balance EUR/2 destinations, and so on.

Invalid example: A posting that credits account:1 with 100 USD/2 without a corresponding debit violates this rule. The total destination increase (100) does not equal the total source increase (0), so the transaction is rejected.

2. The ledger-wide sum is always zero#

Across all accounts, the sum of all destination components always equals the sum of all source components at all times. Assets are never created or destroyed. This invariant holds per asset — the ledger-wide balance of USD/2 is always zero, the ledger-wide balance of EUR/2 is always zero, and so on independently.

3. Accounts cannot go negative by default#

An account's balance cannot fall below zero unless it is explicitly permitted. This prevents accounts from spending assets they do not have.

Invalid example: An account with a balance of 100 USD/2 cannot send 150 USD/2. Doing so would leave it with a balance of −50 USD/2, violating this rule. To allow an account to go below zero, use the allowing overdraft clause in Numscript. See Overdraft.

The world account#

Since no transaction can create assets, there must be a designated way to introduce new assets from outside the system. Note that the ledger tracks assets, not value — for currencies, this typically maps 1:1, but value (e.g. accounting in GBP while holding USD) is not represented in the ledger. There are two patterns.

Using the world account#

The @world account is a built-in account permitted to carry a negative balance. Sending from @world to any destination introduces assets into the ledger; @world's output increases while the recipient's input increases by the same amount.

@world is Formance-specific and has no counterpart in conventional accounting, so it does not map cleanly onto a real-world funding source. It is the fastest way to get a ledger working and it is the right tool for tests, prototypes, and the specific cases where the origin of the assets genuinely is outside your books. For production models where each inflow has an identifiable external counterparty, prefer counter-part accounts below.

Before:

AccountInputOutputBalance
account:1000
world000

Transaction: send 100 USD/2 from world to account:1

After:

AccountInputOutputBalance
account:11000100
world0100-100

The world account carries −100. Total ledger-wide balance: 100 + (−100) = 0.

Using counter-part accounts#

Instead of @world, use named counter-part accounts — one per payment method or external funding source. In accounting terms, these can be treated as Normal Debit asset accounts; their balance is negative because they are the counter-part. They represent the platform's obligation to those external parties.

Example: A customer pays 100 USD/2: 50 via credit card, 50 via bank transfer.

Before:

AccountInputOutputBalance
order:1234000
payment-method:credit-card000
payment-method:bank-transfer000

After:

AccountInputOutputBalance
order:12341000100
payment-method:credit-card050-50
payment-method:bank-transfer050-50

The counter-part accounts carry negative balances representing what was received from each payment method. Reconciliation is straightforward: the balance of payment-method:credit-card is exactly the amount to reconcile against your credit card processor.

Counter-part accounts and reconciliation

By mapping counter-part accounts to your financial partners, you can reconcile your ledger against external systems by comparing each counter-part account's balance against the partner's reported balance.

Overdraft and negative balances#

Some accounts are designed to carry a negative balance: liability accounts, credit lines, or accounts that represent external obligations. The ledger permits this when you explicitly declare it in Numscript using the allowing overdraft clause.

numscript
send [USD/2 1000] (
  source = @users:alice allowing unbounded overdraft
  destination = @vendors:acme
)

You can also cap the overdraft to a specific amount:

numscript
send [USD/2 1000] (
  source = @users:alice allowing overdraft up to [USD/2 500]
  destination = @vendors:acme
)

Example: Alice's account has a zero balance but is permitted to go negative. She purchases USD/2 8000 of software from a vendor:

numscript
send [USD/2 8000] (
  source = @users:alice allowing unbounded overdraft
  destination = @vendors:acme-software
)

Alice's account balance is now −USD/2 8000. When her salary is credited and the balance is settled:

numscript
send [USD/2 8000] (
  source = @payroll
  destination = @users:alice
)

Use allowing overdraft when modeling credit lines, loans, liability accounts (such as counter-part payment method accounts), or any account that legitimately represents an obligation.

Mapping to traditional debit/credit accounting#

This section is for readers familiar with traditional double-entry accounting. If you're new to accounting, you can skip this section.

The golden rule#

The golden rule for converting a credit/debit accounting model to Formance's source/destination model is:

  • Credit becomes Destination
  • Debit becomes Source

Normal accounts#

In accounting practice, accounts are designated as normal debit or normal credit depending on whether they are on the asset or liability side of the balance sheet:

Entry typeFormance roleNormal Debit (trad. balance)Normal Credit (trad. balance)
Debit EntrySourceIncreasesDecreases
Credit EntryDestinationDecreasesIncreases

Conversion examples#

Topping up a wallet with a bank transfer#

A user tops up their wallet with a bank transfer. The user wallet is a liability (normal credit); the bank account is an asset (normal debit).

In the credit/debit model:

AccountDebitCredit
User Wallet$0$100
Bank Account$100$0

Applying the golden rule:

AccountSourceDestinationBalance
User Wallet$0$100$100
Bank Account$100$0-$100

The bank account carries a negative balance here. As an asset account (normal debit), its balance in the source/destination model is negative. Formance supports this with the allowing overdraft clause in Numscript.

Transferring money between two wallets#

User 1 transfers $100 from their wallet to User 2's wallet. Both wallets are liabilities (normal credit).

Starting balances:

AccountBalance
User 1 Wallet$200
User 2 Wallet$0

In the credit/debit model:

AccountDebitCredit
User 1 Wallet$100$0
User 2 Wallet$0$100

Applying the golden rule:

AccountSourceDestinationBalance
User 1 Wallet$100$200$100
User 2 Wallet$0$100$100

Withdrawing money from a wallet#

A merchant withdraws $50 from their wallet to their bank account. The wallet is a liability (normal credit); the bank account is an asset (normal debit).

Starting balances:

AccountBalance
Merchant Wallet$100
Bank Account-$1000

In the credit/debit model:

AccountDebitCredit
Merchant Wallet$50$0
Bank Account$0$50

Applying the golden rule:

AccountSourceDestinationBalance
Merchant Wallet$50$100$50
Bank Account$1000$50-$950

Treasury movement between two bank accounts#

A business moves $250 from a US bank account to a UK bank account. Both are assets (normal debit).

Starting balances:

AccountBalance
US Bank Account-$1000
UK Bank Account-$500

In the credit/debit model:

AccountDebitCredit
US Bank Account$0$250
UK Bank Account$250$0

Applying the golden rule:

AccountSourceDestinationBalance
US Bank Account$1000$250-$750
UK Bank Account$750$0-$750

Asset Account Balances

Asset accounts (normal debit) will have a negative balance in the source/destination model, because their source component (outflows) exceeds their destination component (inflows).

Do / Don't#

  • Do: Use @world as the source when introducing new funds whose real-world origin is tracked outside the ledger, and when getting started or testing.
  • Do: Prefer named counter-part accounts over @world in production models where each inflow has an identifiable external counterparty; they reconcile against your partners, @world does not.
  • Do: Use allowing overdraft explicitly when modeling credit lines, debts, or liability accounts.
  • Don't: Assume any account can go negative; it will fail without the overdraft clause.
  • Don't: Create single-sided postings (source without a destination, or vice versa); the ledger will reject them.