DEV Community

Alena
Alena

Posted on • Originally published at Medium

A .NET Dinosaur in Web3. #2

Day 2: Access Control

Counter.sol - a little better than "Hello World", right?

The goal: write a simple Counter contract - increment, decrement, reset -
with real access rules.

The Contract

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract Counter {
    uint256 public count;
    address public owner;

    constructor() {
        owner = msg.sender;
        count = 0;
    }

    function increment() public {
        count += 1;
    }

    function decrement() public {
        require(count > 0, "Already zero");
        count -= 1;
    }

    function reset() public {
        require(msg.sender == owner, "Only owner can reset!");
        count = 0;
    }
}
Enter fullscreen mode Exit fullscreen mode

GitHub: github.com/alena-dev-soft/solidity-learn/contracts/02day/

What Actually Clicked

In the .NET world we use HttpContext.User to know who's making a request. In Solidity it's msg.sender - the wallet address of whoever called the method. No login system, no JWT, no sessions. Just a cryptographically verified address. The contract knows exactly who you are. Always.

The next thing - calling count to check the current value is free.Simple rule: no transaction, no gas.

But there's a warning that almost everyone forgets - which makes it kind of dangerous for your budget. If you forget to switch from the real network to the test network, those transactions will cost you actual money. Every single one.

The .NET → Solidity Map (So Far)

Solidity .NET equivalent
msg.sender HttpContext.User
require() Guard clause + exception
uint256 uint (unsigned)
address No direct equivalent — wallet ID

Day 2 Score: 10/10

Everything is mapping cleanly to .NET concepts. The mental model is familiar, the syntax is new.

Tomorrow I want something with real-world application - not a toy example, but a contract that actually does something useful.

Stage: Dinosaur 🦕 - mapping the terrain.

Day 3 incoming. 🚀

Top comments (0)