3
contract B {
    event eventFallback();
}

contract A {
    address contractB;

    function () public payable {
         emit B(contractB).eventFallback();
    }
}

I tried like above and failed. Is there a way to emit an event in another contract? (except creating an interface function like below.)

function emitEvent() public {
    emit eventFallback();
}
2

You can not directly emit an event from another contract. The only way to do it is by wrapping the emit into a function (like you described above).

From the perspective of modularity, the point at which an event is emitted, should be in the control of the emitting contract. Everything else would be fragile, since the contract could not make any stable promisses about its interface.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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