-
Notifications
You must be signed in to change notification settings - Fork 0
/
function-modifiers-cont.
46 lines (35 loc) · 1.17 KB
/
function-modifiers-cont.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
pragma solidity ^0.8.0;
contract MyContract {
uint value;
function setValue(uint _value) external {
value = _value;
}
function getValue() external view returns(uint) {
return value;
}
function getNewValue() external pure returns(uint) {
return 3 + 3;
}
}
/* Excercise:
1. create a function called "multiply" which returns 3 multiplied by 7.
2. Create another function called valuePlusThree which returns the state variable value + 3.
3. Successfully deploy the contracts and test for the results.
**Use the appropriate modifying keywords accordingly!!!!!!!
*/
contract pureView {
// The value to be set and manipulated
uint value;
// Function to set the value
function setValue(uint _value) external {
value = _value; // Set the value to the input value
}
// A pure function that multiplies 3 and 7 and returns the result
function multiply() external pure returns(uint) {
return 3 * 7; // Returns the product of 3 and 7
}
// A view function that adds 3 to the value and returns the result
function valuePlusThree() external view returns(uint) {
return value + 3; // Returns the current value plus 3
}
}