Ledger

Quick Start

Create a ledger, record your first transactions, and verify the resulting balances.

Get from zero to your first transactions. By the end you have funded an account, split a payment, and read the resulting balances, all using Numscript.

Estimated effort: 5 minutes

Record your first transaction#

Create a ledger

fctl ledger create main
POST/api/ledger/v2/main

This creates a ledger named main. Every account and transaction in this guide lives here.

Fund a user account

Send $100 from @world (an infinite funding source) to a user account:

numscript
send [USD/2 10000] (
  source = @world
  destination = @user:alice
)
fctl ledger transactions num - --confirm --ledger main <<< 'send [USD/2 10000] ( source = @world destination = @user:alice )'
POST/api/ledger/v2/main/transactions

USD/2 means US dollars with two decimal places, so 10000 represents $100.00. Ledger creates an account on first use.

Split a payment

Alice buys something for $30. The merchant gets 90%, the platform takes 10% as a fee:

numscript
send [USD/2 3000] (
  source = @user:alice
  destination = {
    90% to @merchant:bob
    remaining to @platform:fees
  }
)
fctl ledger transactions num - --confirm --ledger main <<< 'send [USD/2 3000] ( source = @user:alice destination = { 90% to @merchant:bob remaining to @platform:fees } )'
POST/api/ledger/v2/main/transactions

The ledger enforces that Alice has sufficient funds. If she does not, Ledger rejects the whole transaction: no partial execution, no overdraft.

Check balances

fctl ledger accounts list --ledger=main
GET/api/ledger/v2/main/accounts

Ledger returns these balances:

AccountBalance (USD/2)Meaning
user:alice7000$70.00 remaining
merchant:bob2700$27.00 (90% of $30)
platform:fees300$3.00 (10% of $30)

Every cent is accounted for. The sum of all non-world balances equals the total funded.

What just happened#

  • Double-entry: every send creates balanced movements — what leaves one account enters another
  • @world: a special infinite source/sink for money entering and exiting the ledger
  • USD/2: Universal Monetary Notation — the asset type and precision, no floating-point
  • Splits: Numscript natively handles percentage splits with remaining catching rounding
  • Scarcity: the ledger rejects transactions when the source account has insufficient funds