这里有一个简单的合约,你可以在这个合同中获取、增加和减少计数器的大小。
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
contract Counter {
uint public count;
// 获取当前count值
function get() public view returns (uint) {
return count;
}
// 将count值增加1
function inc() public {
count += 1;
}
// 将count值增减去1
function dec() public {
// This function will fail if count = 0
count -= 1;
}
}