89DEVs

simple counter in Solidity

A simple counter that is written in Solidity. It is possible to increment and decrement the count by a specific number. This allows a bit more functionality than the very simple counter that just increments by one. The counter variable is called count and the increment and decrement functions are named after their functionality.


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

// a simple counter written in Solidity

contract Counter {
    // the count state variable
    uint public count;

    // function to increment the count
    function increment (uint n) external {
        count += n;
    }
    
    // function to decrement the count
    function decrement (uint n) external {
        count -= n;
    }
}