Midnight logoMidnight Academy
← back to projects

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

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.

Next: Project 03 — Private Voting →