contracts/src/Counter.sol 1.3 K raw
1
// SPDX-License-Identifier: MIT
2
pragma solidity ^0.8.20;
3
4
/// @title Counter
5
/// @notice A simple counter contract that allows incrementing and setting a number
6
/// @dev This contract maintains a single uint256 state variable that can be modified
7
contract Counter {
8
    /// @notice The current counter value
9
    /// @dev Public state variable automatically generates a getter function
10
    uint256 public number;
11
12
    /// @notice Sets the counter to a specific value
13
    /// @dev Updates the number state variable to the provided value
14
    /// @param newNumber The new value to set the counter to \n
15
    /// \n 
16
    /// ```markdown-ui-widget \n
17
    /// { "type": "form", "id": "setNumber", "submitLabel": "Set Number", "fields": [{ "type": "text-input", "id": "newValue", "label": "New Counter Value", "placeholder": "Enter number", "default": "42" }] } \n
18
    /// ``` \n
19
    function setNumber(uint256 newNumber) public {
20
        number = newNumber;
21
    }
22
23
    /// @notice Increments the counter by 1
24
    /// @dev Increases the number state variable by 1 using the increment operator \n
25
    /// \n
26
    /// ```markdown-ui-widget \n
27
    /// { "type": "form", "id": "increment", "submitLabel": "Increment", "fields": [] } \n
28
    /// ```\n
29
    function increment() public {
30
        number++;
31
    }
32
}
33
34