You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: junior-1/solidity/README.md
+68-2Lines changed: 68 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -69,8 +69,8 @@
69
69
## Типы. Reference types
70
70
71
71
1. Что можешь рассказать про reference types?
72
-
- Data location(storage, memory, calldata)
73
-
- Массивы(динамические и с фиксированной длиной)
72
+
- Data location(storage, memory, calldata)
73
+
- Массивы(динамические и с фиксированной длиной)
74
74
- Структуры
75
75
2. Как получить длину массива?
76
76
3. Как добавлять данные в массив?
@@ -173,3 +173,69 @@ contract C {
173
173
1. Что такое библиотека?
174
174
2. Как подключить библиотеку?
175
175
- Что такое using for?
176
+
177
+
178
+
## Интересные вопросы
179
+
180
+
1. Округление при делении.
181
+
- Какой ожидается результат вызова функции `roundingDivision()`? В чем заключается проблема? Как это можно обойти?
182
+
```solidity
183
+
function roundingDivision() external pure returns (uint256) {
184
+
return uint256(7) / uint256(5);
185
+
}
186
+
```
187
+
- Какой ожидается результат вызова функции `divisionByZero()`?
188
+
```solidity
189
+
function divisionByZero() external pure returns (uint256) {
190
+
return uint256(7) / 0;
191
+
}
192
+
```
193
+
2. Что произойдет при вызове функции `setOwner(addressB, anyAccount)` на контракте A? Чему будет равен вызов функций `manager()` и `owner()`? Почему важен порядок переменных в этих двух контрактах?
194
+
```solidity
195
+
contract A {
196
+
address public manager;
197
+
address public owner;
198
+
199
+
function setOwner(address target, address account) external {
- [Try Catch and all the ways Solidity can revert](https://www.rareskills.io/post/try-catch-solidity)
14
38
15
39
## Unchecked Math
16
40
@@ -25,7 +49,7 @@
25
49
pragma solidity 0.8.0;
26
50
27
51
contract Counter {
28
-
uint8 _counter= 255;
52
+
uint8 _counter= 255;
29
53
30
54
function increase() public payable {
31
55
_counter++;
@@ -42,10 +66,12 @@ contract Counter {
42
66
pragma solidity 0.8.0;
43
67
44
68
contract Counter {
45
-
uint8 _counter= 255;
69
+
uint8 _counter= 255;
46
70
47
71
function increase() public payable {
48
-
unchecked {_counter++;}
72
+
unchecked {
73
+
_counter++;
74
+
}
49
75
}
50
76
51
77
function getCounter() external view returns(uint8) {
@@ -56,16 +82,18 @@ contract Counter {
56
82
57
83
```solidity
58
84
// SPDX-License-Identifier: MIT
59
-
pragma solidity 0.7.0;
85
+
pragma solidity 0.8.0;
60
86
61
87
contract Counter {
62
-
uint8 _counter= 255;
88
+
int8 _counter= -128;
63
89
64
-
function increase() public payable {
65
-
_counter++;
90
+
function decrease() public payable {
91
+
unchecked {
92
+
_counter--;
93
+
}
66
94
}
67
95
68
-
function getCounter() external view returns(uint8) {
96
+
function getCounter() external view returns(int8) {
69
97
return _counter;
70
98
}
71
99
}
@@ -76,13 +104,19 @@ contract Counter {
76
104
pragma solidity 0.8.0;
77
105
78
106
contract Counter {
79
-
int8 _counter= -128;
107
+
uint8 _counter = 255;
80
108
81
-
function decrease() public payable {
82
-
unchecked {_counter--;}
109
+
function increase() public payable {
110
+
unchecked {
111
+
_increase();
112
+
}
83
113
}
84
114
85
-
function getCounter() external view returns(int8) {
115
+
function _increase() private {
116
+
_counter++;
117
+
}
118
+
119
+
function getCounter() external view returns(uint8) {
86
120
return _counter;
87
121
}
88
122
}
@@ -268,7 +302,7 @@ contract Counter {
268
302
269
303
1. Какие есть два возможных способа создания контрактов?
270
304
2. Как создать контракт через new? Что на самом деле внутри происходит при создании таким способом?
271
-
3. Для чего нужен constructor? Сколько раз он вызывается? Можно ли делать перегрузку для constructor?
305
+
3. Для чего нужен constructor? Сколько раз он вызывается? Можно ли делать перегрузку для constructor? Является ли constructor частью байт-кода контракта?
272
306
4. Как передать эфир при создании контракта?
273
307
5. Как создать контракт через create? Как создать контракт через create2? Какие различия между create и create2? Как у них происходит образование адреса контракта? Почему не безопасно создавать через create?
274
308
6. Можно ли каким-то образом передеплоить смарт-контракт на тот же адрес но с другим кодом?
0 commit comments