Skip to content

Commit e140f8c

Browse files
committed
Callback.sol
1 parent 356fa2c commit e140f8c

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

contracts/Callback.sol

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity >=0.8.0;
3+
4+
contract Parent {
5+
uint public parentVariable;
6+
7+
function parentFunc(uint _parentVariable, function(uint) external _callback) public {
8+
parentVariable = _parentVariable;
9+
_callback(_parentVariable * 2);
10+
}
11+
}
12+
13+
contract Child {
14+
address public parentAddress;
15+
uint public childVariable;
16+
17+
constructor(address _parentAddress) {
18+
parentAddress = _parentAddress;
19+
}
20+
21+
function run(uint _newVar) public {
22+
Parent(parentAddress).parentFunc(_newVar, this.callback);
23+
}
24+
25+
function callback(uint _childVariable) external {
26+
childVariable = _childVariable * 2;
27+
}
28+
}

0 commit comments

Comments
 (0)