Counter
Contract Summary
The Counter contract is a simple on-chain counter that maintains individual count values for each principal address. This minimalist contract demonstrates fundamental Clarity data structures and state management patterns.
What this contract does:
Stores a separate counter value for each user (principal)
Provides read-only access to retrieve any user's count
Allows users to increment their own counter by 1
Initializes counters at 0 for new users automatically
What developers can learn:
How to use
define-mapto create key-value storage in ClarityPattern for per-user state management using principal addresses
Using
default-toto handle missing map entries gracefullySimple read-only vs public function distinction
Basic arithmetic operations and map updates with
map-setThe
tx-sendercontext variable for identifying callers
Was this helpful?