Menu

1 / 5

counter-todo: two small Anchor programs that teach PDAs, account sizing and realloc

DEV Community: rust·Abdeldjalil Chougui·7 days ago
#B43WwflF
#devtorust#devto#dev#counter#owner
Long article (1247 words) — no AI summary yet.
Reading 0:00
15s threshold

The first thing that surprises people coming to Solana from web development is that a program has no storage of its own. All state lives in accounts. Every account has a fixed size in bytes, somebody pays rent for those bytes, and the program must decide who is allowed to change them. "Add a row to a table" becomes "derive an address, allocate exactly enough bytes, pay for them, and check the signer".

A counter and a to-do list are the smallest programs that force you through all of that, so that is what I built. counter-todo is two small Anchor programs in one crate.

Before anything else, the warning from the README: not audited, devnet / localnet only. This is a learning project. Do not deploy it to mainnet or use it with real funds.

What it does

Counter. One PDA per user, derived from ["counter", authority] , with increment and decrement using checked arithmetic. An overflow or underflow is an error, not a silent wrap-around.

To-do list.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.