0

Getter and Setter functions in Solidity | by Shlok Kumar | Coinmonks | Feb, 2023

Share

contract Score { 
uint score = 5;
function getScore() public returns (uint) {
return score;
}
function setScore(uint new_score) public {
score = new_score;
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract SimpleStorage {
// State variable to store a number
uint public num;
// You need to send a transaction to write to a state variable.
function set(uint num) public {
num = num;
}
// You can read from a state variable without sending a transaction.
function get() public view returns (uint) {
return num;
}
}

Join Coinmonks Telegram Channel and Youtube Channel get daily Crypto News

#Getter #Setter #functions #Solidity #Shlok #Kumar #Coinmonks #Feb