A simple in-memory ledger models balances as a dict and transfers as validated state transitions, which mirrors (in miniature) how a blockchain's state transition function works.
python
class Ledger:
def __init__(self):
self.balances: dict[str, float] = {}
def mint(self, to: str, amount: float) -> None:
self.balances[to] = self.balances.get(to, 0) + amount
def transfer(self, frm: str, to: str, amount: float) -> None:
if self.balances.get(frm, 0) < amount:
raise ValueError("insufficient balance")
self.balances[frm] -= amount
self.balances[to] = self.balances.get(to, 0) + amountAn important invariant: total supply (sum of all balances) should only change on `mint`/`burn`, never on `transfer`. Testing this invariant after each operation catches logic bugs early — the same principle underlies real smart contract auditing.