-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathday1.sol
106 lines (74 loc) · 1.83 KB
/
day1.sol
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
The topics we covered:
Solidity - Comments
Solidity - Types
Solidity - Variables
Solidity - Variable Scope
*/
// this is the code that John has written today so far. --- single-line comment
/*
This is the Technical Writing Workshop that will last for a month.
A lot of great technical writers and documentation engineers will be bred here.
*/
/*
1. Uint
this means Unsigned Integer
used for numbers
uint256
2. bool
This is for yes or no
Boolean value or integer
3. String
This is used for words in alphabets
Example: string laptop
4. address
This points to where tokens can be stored or a source of identity
*/
pragma solidity ^0.5.0;
contract SolidityTest {
address public john;
uint storedData; // State variable
constructor() public {
storedData = 10;
}
function getResult() public view returns(uint){
uint a = 1; // local variable
uint b = 2;
uint result = a + b;
return result; //access the local variable
}
}
// msg.sender = john;
// msg.value =
/*
Scope: use it for defining the extent to which a variable or function can be seen or interacted.
Public scope: Makes everything readable and accessible
Private: opposite of the above
*/
pragma solidity ^0.5.0;
contract C {
uint public data = 30;
uint internal iData= 10;
function x() private returns (uint) {
data = 3; // internal access
return data;
}
}
contract Caller {
C c = new C();
function f() public view returns (uint) {
return c.data(); //external access
}
}
contract D is C {
function y() public returns (uint) {
iData = 3; // internal access
return iData;
}
function getResult() public view returns(uint){
uint a = 1; // local variable
uint b = 2;
uint result = a + b;
return storedData; //access the state variable
}
}