Assignment 5
Write two smart contracts caller and callee.
The callee contract should implement a function called sum() that expects two input parameters a and b of type uint256. The function should return the sum of a and b. If you like, you can store the result in a pulbic state variable.
The caller contract should implement a function called invokeRemoteSum() that calls the function sum() in the callee contract. The function should expect the parameters _a and _ b of the correct type and pass them to the function call.
The caller contract should store the returned value in a public state variable called result.
Try them out.
Solution
Callee
pragma solidity 0.8.13;
contract Callee{
uint256 public result;
function sum(uint256 _a, uint256 _b) public returns (uint256){
result = _a + _b;
return result;
}
}
Caller
pragma solidity 0.8.13;
contract Caller{
bytes public result;
address public calleeAddress = ADD CALLEE ADDRESS HERE;
function callRemoteSum(uint256 _a, uint256 _b) public {
(bool success, bytes memory returnData) = calleeAddress.call(
abi.encodeWithSignature("sum(uint256,uint256)", _a, _b)
);
require(success, "Kein sucess");
result = returnData;
}
}