Skip to content

Instantly share code, notes, and snippets.

@sandoche
Created October 2, 2022 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sandoche/e6d9e9fedc508371a4ad8ea633e003dd to your computer and use it in GitHub Desktop.
Save sandoche/e6d9e9fedc508371a4ad8ea633e003dd to your computer and use it in GitHub Desktop.
Example of a Counter in Solidity (for a blog post)
// 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