Skip to main content
ConceptsMeta-tools

codespar_ledger

Double-entry ledger — record money movement, read balances, create accounts. Routes to the tenant's self-hosted Lerian Midaz. Typed wrapper session.ledger(args).

2 min read

codespar_ledger

Meta-tool

codespar_ledger is your system of record / books — an immutable, auditable double-entry ledger. It is distinct from codespar_pay and codespar_charge, which move real money through PSPs; the ledger records what happened. Routes to the tenant's self-hosted Lerian Midaz (multi-currency, multi-asset). Covered by the session.ledger(args) typed wrapper.

Actions

The action argument picks the operation:

actionPurpose
entry (default)Post an n:n journal entry — source debits must equal destination credits
balanceRead an account's balances
accountCreate an account

The ledger is asset-agnostic — no currency or country needed. Amounts are in minor units (centavos, satoshis, …) with a per-asset scale.

Typed wrapper

// Post a journal entry: move 150.00 BRL from a wallet to revenue
const entry = await session.ledger({
  action: "entry",
  asset: "BRL",
  scale: 2,
  source: [{ account: "@wallet/user_123", amount: 15000 }],
  destination: [{ account: "@revenue/store", amount: 15000 }],
  description: "Order #1234 settled",
});

// Read a balance
const balance = await session.ledger({ action: "balance", account: "<account-uuid>" });

// Create an account
const account = await session.ledger({
  action: "account",
  alias: "@wallet/user_123",
  name: "User 123 wallet",
  type: "deposit",
});
entry = session.ledger({
    "action": "entry",
    "asset": "BRL",
    "scale": 2,
    "source": [{"account": "@wallet/user_123", "amount": 15000}],
    "destination": [{"account": "@revenue/store", "amount": 15000}],
    "description": "Order #1234 settled",
})

Direct execute

const balance = await session.execute("codespar_ledger", {
  action: "balance",
  account: "<account-uuid>",
});

Args shape

FieldTypeRequiredDescription
action"entry" | "balance" | "account"NoDefaults to "entry"
assetstringentry, accountAsset / currency code (BRL, USD, USDC, …)
scalenumberNoDecimal places for the asset (default 2; JPY=0, most crypto=6/8)
sourcearrayentryDebit side(s): [{ account (alias), amount (minor units) }]
destinationarrayentryCredit side(s): same shape as source
descriptionstringNoTransaction description (entry only)
accountstringbalanceAccount UUID to read balances for
aliasstringaccountAccount alias, e.g. @wallet/user_123
namestringaccountAccount display name
typestringNoMidaz account type: deposit, savings, external (default deposit)
metadataobjectNoFree-form metadata stored on the entry / account

Operator setup

  • Lerian Midaz — the ledger is the tenant's own Midaz instance. The operator connects it once in /dashboard/auth-configs; credentials are stored in the vault. See Lerian Midaz for self-hosting.

See also

codespar_ledger | CodeSpar