4

I want to use delegatecall in one function to populate an event from the contract I'm calling. Here's a minimal example:

contract Caller {
    address public callee;

    function Caller(address _callee) {
        callee = _callee;
    }

    function delegate() {
        callee.delegatecall(bytes4(keccak256("call()")));
    }
}

contract Callee {
    function call() {
        Log(msg.sender);
    }
    event Log(address sender);
  }

However, the receipt I get in my truffle contracts return an empty array for the logs. Does delegatecall not push the log into the receipt?

I want to be able to "return" a value from the delegatecall.

0

1 Answer 1

0

Your Callee contract is declaring the event but you have to emit it.

contract Callee {

    event Log(address sender);
    
    function call() {
       emit Log(msg.sender);
    }
}

Also note that a contract cannot listen to another contract event. So you will have to listen to Callee events from the front end.

4
  • Are you sure about the last part? I would think that since delegateCall was used, the event would be logged with the Caller contract as emitter.
    – Undead8
    Oct 19, 2021 at 18:42
  • I'm pretty sure a contract cannot listen for another contract events. Because even if it was, it wouldn't be able to return anything from a view call or perform any action that require gas. So it wouldn't do nothing. Oct 19, 2021 at 19:34
  • Yes, a contract cannot listen to an event. What I meant is that you wrote that he has to listen to Callee events from the front end. I think that he has to listen to Caller events instead, since delegateCall would make the event belong to the Caller, not the Callee.
    – Undead8
    Oct 19, 2021 at 20:02
  • Well if he want's to listen for an event in the Caller then the event should be emitted from the Caller when ever a delegate call happens. Oct 19, 2021 at 20:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.