Dec 19, 2023
Tutorials
ZxStim
Counter
simple contract that you can get, increment and decrement the count
value stored in this contract.// SPDX-License-Identifier: MIT
comment in your solidity file. Without the license identifier, the Solidity Compiler will produce a warning but not error.pragma
specifies the compiler version of Solidity.Compile and deploy the code block below:
solidityCounter.sol// SPDX-License-Identifier: MIT pragma solidity ^0.8.20; 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; } }