envoy1084
/
30-Days-of-Solidity
30 Days of Solidity step-by-step guide to learn Smart Contract Development.
WARNING: This repository is currently undergoing updates and revisions to incorporate the latest information and advancements in Solidity programming. Please be advised that the content may not be up-to-date or accurate during this time. We expect the updates to be completed within the next 30 days, and appreciate your patience during this process. Thank you for your understanding.
Contents
- Day 1 - Licenses and Pragma
- Day 2 - Comments
- Day 3 - Initializing Basic Contract
- Day 4 - Variables and Scopes
- Day 5 - Operators
- Day 6 - Types
- Day 7 - Functions
- Day 8 - Loops
- Day 9 - Decision Making
- Day 10 - Arrays
- Day 11 - Array Operations
- Day 12 - Enums
- Day 13 - Structs
- Day 14 - Mappings
- Day 15 - Units
- Day 16 - Require Statement
- Day 17 - Assert Statement
- Day 18 - Revert Statement
- Day 19 - Function Modifiers
- Day 20…
This is Day 7 of 30 in Solidity Series
Today I Learned About Functions in Solidity.
A function is basically a group of code that can be reused anywhere in the program, which generally saves the excessive use of memory and decreases the runtime of the program. Creating a function reduces the need of writing the same code over and over again.
Syntax -
function function_name(parameter_list) scope returns(return_type) {
// block of code
}
eg-
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
contract MyContract {
function add() public view returns (uint256) {
uint256 num1 = 10;
uint256 num2 = 16;
uint256 sum = num1 + num2;
return sum;
}
function sqrt(uint256 num) public pure returns (uint256) {
num = num**2;
return num;
}
}
view in a function ensures that they will not modify the state of the function.
Top comments (0)