Assignment 5

Published by Mario Oettler on

Last Updated on 23. March 2023 by Martin Schuster

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;
    }
}
Categories:

https://blockchain-academy.hs-mittweida.de/wp-content/uploads/2021/04/logo_bcam_rgb_gross.png

Welcome

Blockchain Academy

Continue with credential

No account yet?

Powered by Hidy

Register with Hidy


Register
Sign in

We need the following credential to register:

please select:

To create a new account, we need the following data from you:

We would appreciate the following additional information from you for the creation of your account:

Welcome

Blockchain Academy

Continue with credential

Already have an account?

Powered by Hidy

Sign in with Hidy


Register
Sign in

We need the following credential to log in:

please select: