beginner

Counter Contract

20 min
3 objectives
Now let's build something a bit more interactive - a counter contract! This is a classic example that demonstrates state management in smart contracts. ## Your Task Create a counter contract that: 1. Stores a count value using `StorageU256` 2. Has a function to get the current count 3. Has a function to increment the count 4. Has a function to decrement the count ## Key Concepts - `StorageU256` stores unsigned 256-bit integers - Use `.get()` and `.set()` to read and write values - The `U256` type from `alloy_primitives` represents big numbers

Learning Objectives

  • Work with numeric storage types
  • Implement multiple contract functions
  • Understand state mutations
lib.rs

Click "Run Code" to validate your solution