Ledger ADTs
Reference for Midnight's ledger abstract data types for on-chain state management.
Available ADTs
| ADT |
Purpose |
Key Operations |
Cell<T> |
Single mutable value |
read, write |
Counter |
Increment-only counter |
increment, value |
Map<K, V> |
Key-value storage |
lookup, insert, remove |
Set<T> |
Membership collection |
member, insert, remove |
List<T> |
Ordered collection |
append, nth, length |
MerkleTree<T> |
Membership proofs |
insert, root, pathForLeaf |
HistoricMerkleTree<T> |
Historical roots |
Same + resetHistory |
Quick Examples
Counter
ledger counter: Counter;
export circuit increment(): Uint<64> {
counter.increment(1);
return counter.value();
}
Map
ledger balances: Map<Bytes<32>, Uint<64>>;
export circuit get_balance(user: Bytes<32>): Uint<64> {
const result = balances.lookup(user);
return if result is Maybe::Some(balance) { balance } else { 0 };
}
MerkleTree
ledger members: MerkleTree<Bytes<32>>;
export circuit prove_membership(
leaf: Bytes<32>,
path: Vector<Bytes<32>, 20>
): Boolean {
const computed_root = merkleTreePathRoot(leaf, path);
return computed_root == members.root();
}
Compact vs TypeScript Operations
Some ADT operations are only available in TypeScript:
| ADT |
Compact |
TypeScript Only |
| Counter |
value, increment |
- |
| Map |
lookup, insert, remove |
entries, keys |
| Set |
member, insert, remove |
entries, size |
| List |
nth, append |
entries, length |
| MerkleTree |
insert, root |
pathForLeaf, iteration |
References
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: compact-coreledger-adts3description: Use when working with Compact on-chain state management using ledger ADTs including Cell, Counter, Map, Set, List, MerkleTree, or HistoricMerkleTree, or when needing to understand which operations are available in Compact vs TypeScript.4---56# Ledger ADTs78Reference for Midnight's ledger abstract data types for on-chain state management.910## Available ADTs1112| ADT | Purpose | Key Operations |13|-----|---------|----------------|14| `Cell<T>` | Single mutable value | `read`, `write` |15| `Counter` | Increment-only counter | `increment`, `value` |16| `Map<K, V>` | Key-value storage | `lookup`, `insert`, `remove` |17| `Set<T>` | Membership collection | `member`, `insert`, `remove` |18| `List<T>` | Ordered collection | `append`, `nth`, `length` |19| `MerkleTree<T>` | Membership proofs | `insert`, `root`, `pathForLeaf` |20| `HistoricMerkleTree<T>` | Historical roots | Same + `resetHistory` |2122## Quick Examples2324### Counter25```compact26ledger counter: Counter;2728export circuit increment(): Uint<64> {29 counter.increment(1);30 return counter.value();31}32```3334### Map35```compact36ledger balances: Map<Bytes<32>, Uint<64>>;3738export circuit get_balance(user: Bytes<32>): Uint<64> {39 const result = balances.lookup(user);40 return if result is Maybe::Some(balance) { balance } else { 0 };41}42```4344### MerkleTree45```compact46ledger members: MerkleTree<Bytes<32>>;4748export circuit prove_membership(49 leaf: Bytes<32>,50 path: Vector<Bytes<32>, 20>51): Boolean {52 const computed_root = merkleTreePathRoot(leaf, path);53 return computed_root == members.root();54}55```5657## Compact vs TypeScript Operations5859Some ADT operations are only available in TypeScript:6061| ADT | Compact | TypeScript Only |62|-----|---------|-----------------|63| Counter | `value`, `increment` | - |64| Map | `lookup`, `insert`, `remove` | `entries`, `keys` |65| Set | `member`, `insert`, `remove` | `entries`, `size` |66| List | `nth`, `append` | `entries`, `length` |67| MerkleTree | `insert`, `root` | `pathForLeaf`, iteration |6869## References7071- [Counter](./references/counter.md) - Counter operations and patterns72- [Collections](./references/collections.md) - Map, Set, List operations73- [Merkle Trees](./references/merkle-trees.md) - MerkleTree and HistoricMerkleTree74- [Kernel](./references/kernel.md) - Special kernel operations7576---77> Converted and distributed by [TomeVault](https://tomevault.io/claim/aaronbassett) — claim your Tome and manage your conversions.78<!-- tomevault:4.0:skill_md:2026-04-14 -->