Ledger Agnostic Providers

By ManOguaR — September 04, 2025

A step towards a unified ledger programming model in .NET

In The Corporate Wars, we needed a way to interact with a blockchain ledger without exposing our core systems to low-level details such as signatures, serialization, and network constraints.
To solve this, we created the Ledger Provider, a component that unifies how our services read and write game state to the ledger.

The goal is to simplify and standardize the programming model, much like a data provider does for databases. By defining a clear contract, we can work with domain objects while keeping the underlying implementation hidden and replaceable.


How it works

At the lowest level of the simulation (LOD0), the global economic tick advances the persistent game state.
The provider turns each tick into a batch of ledger operations, handling:

  1. Preparation – Grouping reads and writes.
  2. Execution – Submitting the batch with tick-level idempotency.
  3. Tracing – Returning results and errors for telemetry and recovery.

Example usage

var provider = ledger.GetProvider();
using var uow = provider.BeginBatch(new BatchOptions { TickId = tick.Id });

var world = await provider.ReadAsync<WorldState>(worldId);

uow.Write(new TransferMCr { From = bank, To = corp, Amount = 125_000m });
uow.Write(new MintRU { World = world.Id, Units = 500 });

var result = await uow.CommitAsync();
if (!result.Success) Handle(result.Errors);

The domain code remains focused on game domain concepts, while the provider takes care of:

  • Encodings and signatures,
  • Network limits and fees,
  • Error mapping and retries.

Benefits

  • Unified contract – A consistent way to interact with the ledger.
  • Encapsulation – Domain logic is independent from blockchain details.
  • Flexibility – Different providers can be swapped without changing the core code.
  • Safety – Idempotent batches prevent duplicated effects on retries.

This approach gives us a stable foundation to evolve the economic simulation while staying clear of low-level ledger complexity.