Increment/Decrement in solidity smart contract
eluconsmidar
Posted on May 8, 2024
Here is a simple contract that you can get, increment and decrement the count store in this contract.
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
contract Counter {
uint256 public count;
// Function to get the current count
function get() public view returns (uint256) {
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;
}
}
💖 💪 🙅 🚩
eluconsmidar
Posted on May 8, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.