Skip to content

Instantly share code, notes, and snippets.

@raj-pranav
Created January 29, 2022 20:53
Show Gist options
  • Save raj-pranav/fff69c99ff8fb1d6ae172aa86b13d077 to your computer and use it in GitHub Desktop.
Save raj-pranav/fff69c99ff8fb1d6ae172aa86b13d077 to your computer and use it in GitHub Desktop.
Functions in Solidity
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.5.0 <0.9.0;
// code for view type function
contract sample {
uint s = 10;
function f_name(uint _a) public view returns (uint) {
return _a + block.number;
}
}
// code for pure type function
contract sample_pure {
function sample_p (uint _age) public pure returns (bool) {
if (_age > 60) // to check senior citizen
return true;
else
return false;
}
}
// One liner function
contract Test {
function f(uint a) private pure returns (uint) { return a + 1; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment