chapter26-code-2
Thu Mar 30 2023 11:42:17 GMT+0000 (Coordinated Universal Time)
Saved by
@RareSkills
// ------------------ V1 -------------------
contract GetSumV1 {
// note we changed call to staticcall
// public --> external
// added a view modifier
function getSum(address adder, uint256 a, uint256 b) external view returns (uint256) {
(bool ok, bytes memory result) = adder.staticcall(abi.encodeWithSignature("add(uint256,uint256)", a, b));
require(ok, "call failed");
uint256 sum = abi.decode(result, (uint256));
return sum;
}
}
contract Adder {
// view changed to pure
function add(uint256 a, uint256 b) external pure returns (uint256) {
return a + b;
}
}
content_copyCOPY
Comments