-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path29-call-delegatecall-staticcall.sol
More file actions
45 lines (37 loc) · 1.28 KB
/
29-call-delegatecall-staticcall.sol
File metadata and controls
45 lines (37 loc) · 1.28 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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
contract A {
int8 public s_val;
function deneme(int8 a) public returns(int8) {
s_val = a;
return a;
}
function deneme2(int8 a) public view returns(int8) {
return s_val + a;
}
}
contract CallAFunctions {
int8 public s_val;
address public s_addr;
constructor(address _addr) {
s_addr = _addr;
}
function denemeCall(int8 _newVal) public returns(int8) {
(bool success, bytes memory result) = s_addr.call(abi.encodeWithSignature("deneme(int8)", _newVal));
require(success, "call failed");
int8 a = abi.decode(result, (int8));
return a;
}
function denemeDelegatecall(int8 _newVal) public returns(int8) {
(bool success, bytes memory result) = s_addr.delegatecall(abi.encodeWithSignature("deneme(int8)", _newVal));
require(success, "call failed");
int8 a = abi.decode(result, (int8));
return a;
}
function denemeStaticcall(int8 _newVal) public view returns(int8) {
(bool success, bytes memory result) = s_addr.staticcall(abi.encodeWithSignature("deneme2(int8)", _newVal));
require(success, "call failed");
int8 a = abi.decode(result, (int8));
return a;
}
}