-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStorage Smart Contract.sol
More file actions
71 lines (39 loc) · 1.71 KB
/
Storage Smart Contract.sol
File metadata and controls
71 lines (39 loc) · 1.71 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
Objective
This challenge will help you to learn how to save and retrieve values in smart contracts. Read and Write operations are the most important operations in any system, with this simple problem statement you will be able to understand how the read and write operations are done in smart contracts on the blockchain.
Task
1. Create a private variable to store an Integer value.
2. Create a store() function to assign value to the created variable in the smart contract.
3. Create a retrieve() function to retrieve the stored value from the variable.
*note: keep the function names as it is.
Task Description
In this challenge, you need to save value to the smart contract and retrieve that value.
1. You will save that value in the form of a variable, it is a simple initialization of a variable.
example -
int a = 23;
Now if you have to change the value of 'a' you can set this value through a function written in the smart contract.
You can learn more about solidity in this course on DApp World itself for free
Here is how you write a function in smart contracts :
function change_value(int _a ) public returns( int ) {
. . .
}
2. Now you have to read or retrieve the value of the same variable. In smart contracts you can do that through functions, you simply have to return the value of the variable using a function.
Sample Input 0
1000
Sample Output
1000
*/
//PROGRAM
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;
contract Storage {
int private num;
//this function stores an integer
function store(int _a) public {
num=_a;
}
//this function returns the stored integer
function retrieve() public view returns(int) {
return num;
}
}