Example Implementations
Explore detailed examples of common financial operation patterns:Omnibus Accounts
Managing pooled funds at financial institutions while tracking individual customer liabilities
Payment Acceptance
Handling card payment authorizations, settlements, refunds, and chargebacks
Financial Hosting & Issuing
Operating an issuing program with authorization holds, presentments, and scheme settlements
Stablecoin Operations
Managing on-ramp and off-ramp flows between fiat and blockchain-based stablecoins
Purpose of This Section
These example implementation patterns serve multiple goals:- Demonstrate Real-World Patterns: Show how common financial operations can be modeled using the Formance Ledger
- Illustrate Numscript’s Power: Highlight how Numscript acts as a bridge between business intent and technical implementation
- Provide Starting Templates: Offer patterns you can adapt to your specific needs
- Show Best Practices: Demonstrate proper account structures, metadata usage, and transaction modeling
Intent-Based Finance
At the heart of the Formance approach is the concept of Numscript as an intent layer. This means:Separation of Concerns
1
Define Actors and Accounts
Your business and finance teams identify all parties involved in your operations: customers, banks, payment processors, internal accounts, liability accounts, etc.Each actor is represented by accounts in the ledger with clear naming conventions and metadata.
2
Map Events and Bookings
Together, teams enumerate all the financial events that can occur in your business: deposits, withdrawals, authorizations, settlements, refunds, chargebacks, minting, burning, etc.Each event translates to specific accounting movements between accounts.
3
Write Numscripts
Once actors, accounts, and events are defined, Numscripts encode the business logic. These scripts become the single source of truth that both business and technical teams can read and validate.
4
Execute with Variables
When events occur in your system, you simply “play” the appropriate Numscript with the correct variables. The ledger handles the rest: validating constraints, recording transactions, maintaining balances.
Benefits of This Approach
- Business Clarity: Finance and operations teams can understand and validate the logic without deep technical knowledge.
- Rapid Iteration: Changes to business logic require updating Numscripts, not redeploying entire systems.
- Consistency: The same Numscript produces the same results, eliminating implementation drift across services.
Leveraging Bi-Temporality
A critical feature of the Formance Ledger is bi-temporality, which means every transaction tracks two timestamps:- Request Time: When the transaction was submitted to the ledger (machine clock time)
- Transaction Time: When the transaction is considered to have occurred (business effective time)
Why This Matters for Financial Operations
In real-world financial operations, you frequently encounter timing mismatches:- Settlement Delays: Payment authorizations happen in real-time, but bank settlements occur T+1 to T+3 days later. Your ledger should reflect the true effective dates of these movements, not just when you learned about them.
- Batch Processing: Bank statements arrive the next day. You need to record yesterday’s transactions with their correct effective timestamps.
- Corrections and Adjustments: When errors are discovered or chargebacks occur, you may need to backdate transactions to reflect when they truly should have occurred.
- Multi-Timezone Operations: Events happening in different timezones need consistent temporal representation.
Implementing Bi-Temporality in Your Numscripts
When executing Numscripts for real-world events, always provide the appropriate transaction timestamp, if reporting for point in time balances of accounts is important:Request with Transaction Time
If you don’t specify a timestamp, the ledger uses the current machine time.
Querying at Points in Time
Bi-temporality enables powerful queries:Query Balance at Specific Time
- Reconciliation: Match ledger state to bank statements from specific dates
- Compliance: Show regulators your exact position at any historical moment
- Auditing: Investigate what the system knew and when
- Reporting: Generate month-end reports with exact balance snapshots
How to Use These Examples
Each example implementation follows a consistent structure:- Concept Introduction: Explains the financial operation in plain language
- Key Concepts & Terminology: Defines important terms and patterns specific to the operation
- System Actors: Identifies all parties, their roles, and account types (using interactive tabs)
- Account Structure: Shows how to organize accounts in the ledger with clear naming conventions
- Balances & Periods: Explains timing considerations and balance tracking
- Movements & Bookings: Details each financial event with complete Numscript implementations
- Executable Examples: Provides playground-linked examples for each transaction type
- Advanced Features: Demonstrates how to leverage bi-temporality, metadata, and other ledger capabilities
- Next Steps: Links to related implementations and resources
Some edge cases and special scenarios are covered within each transaction pattern section. The issuing financial host implementation includes additional querying patterns for operational monitoring.
Adapting to Your Needs
1
Understand the Pattern
Read through the full example to grasp the core concepts and structure.
2
Map to Your Business
Identify how the pattern differs from your specific use case. What actors are different? What events are unique to you?
3
Modify Account Structure
Adapt the account naming and hierarchy to match your organizational needs and reporting requirements.
4
Customize Numscripts
Adjust the scripts to reflect your business rules, constraints, and metadata requirements.
5
Test Thoroughly
Use the sandbox environment to test your adapted patterns with realistic scenarios, including edge cases and error conditions.
6
Validate with Stakeholders
Review the adapted Numscripts with your finance, compliance, and operations teams to ensure alignment.
Key Capabilities Demonstrated
Throughout these example implementations, you’ll see how the Formance Ledger handles:Multi-Asset Operations
Accounts are multi-asset by default. The same account structure and Numscripts work across USD, EUR, GBP, stablecoins, or any other asset you define.Numscript Multi-Asset Example
$ASSET variable makes the script reusable across all currencies.
Rich Metadata
Attach business context to accounts and transactions directly within your Numscripts for powerful querying, reporting, and integration. Useset_tx_meta() to add metadata to transactions and set_account_meta() to update account metadata:
Card Authorization with Metadata
Metadata can be any type: strings, numbers, monetary values, portions, or even account references. See the Numscript metadata reference for complete details.
Flexible Querying
Find exactly what you need using filters on metadata, balances, timestamps, and more:Example Queries
Constraint Enforcement
Define business rules that the ledger automatically enforces:- Prevent overdrafts on customer accounts
- Ensure sufficient reserves for liabilities
- Validate transaction amounts and parties
- Block transactions that violate business logic
Remember: these are starting points, not finished solutions. Your business is unique, and your ledger implementation should reflect that uniqueness while maintaining the clarity and auditability that Formance enables.