Created
October 2, 2022 15:59
-
-
Save sandoche/e6d9e9fedc508371a4ad8ea633e003dd to your computer and use it in GitHub Desktop.
Example of a Counter in Solidity (for a blog post)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.13; | |
contract Counter { | |
uint public count; | |
// Function to get the current count | |
function get() public view returns (uint) { | |
return count; | |
} | |
// Function to increment count by 1 | |
function inc() public { | |
count += 1; | |
} | |
// Function to decrement count by 1 | |
function dec() public { | |
// This function will fail if count = 0 | |
count -= 1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment