Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@aunyks
Last active March 10, 2023 10:33
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save aunyks/22be27444d6a9a91d2305c2ea2e2f7e8 to your computer and use it in GitHub Desktop.
Save aunyks/22be27444d6a9a91d2305c2ea2e2f7e8 to your computer and use it in GitHub Desktop.
A simple counter written in Solidity, for Ethereum.
pragma solidity ^0.4.0;
contract Counter {
int private count = 0;
function incrementCounter() public {
count += 1;
}
function decrementCounter() public {
count -= 1;
}
function getCount() public constant returns (int) {
return count;
}
}
@vikiival
Copy link

vikiival commented Mar 2, 2022

for the new version of solidity.

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

contract TestCounter {
    int private count = 0;
    function incrementCounter() public {
        count += 1;
    }
    function decrementCounter() public {
        count -= 1;
    }

    function getCount() public view returns (int) {
        return count;
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment