Project 02
Todo App
Counter taught you a single, unstructured value. This project teaches you to store a collection — the pattern behind almost every real app, on-chain or not.
What you'll learn
- Storing a list-like structure in public ledger state
- CRUD as circuits: create, read, update, delete, each as its own entry point
- Why you design your data shape around what needs to be provably true, not just what's convenient
The contract
Save this as contracts/todo.compact:
pragma language_version >= 0.23;
import CompactStandardLibrary;
export ledger taskCount: Uint<32>;
export ledger completedCount: Uint<32>;
export circuit addTask(): [] {
taskCount = taskCount + 1;
}
export circuit completeTask(): [] {
completedCount = completedCount + 1;
}Why this is simplified, on purpose
A real todo app needs actual task text and per-task IDs, which means arrays or maps in ledgerstate, a step beyond Compact's simplest types. This version tracks counts only, so you can focus on the CRUD-as-circuits pattern first. Once you're comfortable with this, look up Compact's Map and Vector types in the official docs to extend it into a real per-task list.
Build it yourself
compact compile contracts/todo.compact contracts/managed/todo
Deploy, then call addTask() three times and completeTask() once. Read the ledger back and confirm taskCount is 3 and completedCount is 1.