1

Are event emitted when a contract calls selfdestruct?


In the following example, the event is not emitted/logged:

pragma solidity ^0.4.17;

contract Test {
    address owner;

    constructor() public {
        owner = msg.sender;
    }

    event dying(bool dead);

    function kill() public {
        selfdestruct(owner);
        emit dying(true);
    }
}

2 Answers 2

2

I just tested it, and the events do get emitted. See:

pragma solidity ^0.4.17;

contract Test {
    address owner;

    constructor() public {
        owner = msg.sender;
    }

    event dying(bool dead);

    function kill() public {
        emit dying(true);
        selfdestruct(owner);
    }
}
1
  • the events are emitted becase you use emit keyword, not because you are selfestructing a contract
    – Nulik
    Commented Aug 30, 2018 at 17:28
0

You have to emit the event before actually calling selfdestruct. When calling selfdestruct the contract code is being deleted, that is why an event will not be emitted anymore.

So only change the order of your code, so that selfdestruct is on the last line.

Your Answer

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

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