Assignment 6

Published by Mario Oettler on

Last Updated on 23. March 2023 by Martin Schuster

Write two contracts caller and calleeDelegate.

The contract calleeDelegate should implement a function sum() that receives two parameters _a and _b of type uint256. It should calculate the sum and store the result in a public contract variable result.

The contract caller should implement a function invokeRemoteSum() that passes the arguments _a and _b to the function sum() in the calleeDelegate contract via a delegate call.

The contract caller should declare a public state variable result of type uint256;

Try the contracts out and check the values of both variables result if the function sum() is called directly from the contract calleeDelegate or via the caller contract.

Solution

calleeDelegate

pragma solidity 0.8.13;

contract callee{
    uint256 public result;

    function sum(uint256 _a, uint256 _b) public{
        result = _a + _b;
    }
}

Caller

pragma solidity 0.8.13;

contract callerDelegate{

    uint256 public result;
    address public callee = 0xDA07165D4f7c84EEEfa7a4Ff439e039B7925d3dF;

    function invokeRemoteSum() public{
        (bool success, bytes memory data) = callee.delegatecall(
            abi.encodeWithSignature("sum(uint256,uint256)", 10,14)
        );
    }
}
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: