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
+70-2Lines changed: 70 additions & 2 deletions
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. Как добавлять данные в массив?
@@ -150,6 +150,8 @@ contract C {
150
150
3. Зачем нужны специальные функции fallback и receive?
151
151
- Что будет если отправить в контракт эфир где нет fallback/receive?
152
152
4. Как работает перегрузка функций?
153
+
5. Что такое "free functions" или другое название функции за пределами контракта? В чем их особенность?
154
+
- Может ли такая функция посылать ether, вызывать другие контракты, получить доступ к `this`, переменной из storage?
153
155
154
156
## Наследование
155
157
@@ -173,3 +175,69 @@ contract C {
173
175
1. Что такое библиотека?
174
176
2. Как подключить библиотеку?
175
177
- Что такое using for?
178
+
179
+
180
+
## Интересные вопросы
181
+
182
+
1. Округление при делении.
183
+
- Какой ожидается результат вызова функции `roundingDivision()`? В чем заключается проблема? Как это можно обойти?
184
+
```solidity
185
+
function roundingDivision() external pure returns (uint256) {
186
+
return uint256(7) / uint256(5);
187
+
}
188
+
```
189
+
- Какой ожидается результат вызова функции `divisionByZero()`?
190
+
```solidity
191
+
function divisionByZero() external pure returns (uint256) {
192
+
return uint256(7) / 0;
193
+
}
194
+
```
195
+
2. Что произойдет при вызове функции `setOwner(addressB, anyAccount)` на контракте A? Чему будет равен вызов функций `manager()` и `owner()`? Почему важен порядок переменных в этих двух контрактах?
196
+
```solidity
197
+
contract A {
198
+
address public manager;
199
+
address public owner;
200
+
201
+
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