2

Can I call another contract that eventually will call selfdestruct, and keep executing my function?

For example, say I have two contracts as follows:

contract Destructor {
    address owner;

    constructor() {
        owner = msg.sender;
    }

    function done() public {
        selfdestruct(owner);
    }
}

contract Test {
    ...
    function test(address dtor) public returns(bool) {
        Destructor(dtor).done();
        // Can I keep execution here after dtor was destructed?
        bla += 42;
        return true;
    }
}

will bla += 42; be executed and test() will return true?

2

Yes.

Here's a cleaned up version of the contracts.

pragma solidity 0.5.2;

contract Destructor {

    address payable owner;

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

    function done() public {
        selfdestruct(owner);
    }
}

contract Test {

    uint public bla;

    function test(address dtor) public returns(bool) {
        Destructor(dtor).done();
        bla += 42;
        return true;
    }
}

And here is 42 in Remix to show it working.

enter image description here

Hope it helps.

  • Thanks! So I could just try to run my test instead of asking here :) – avim Jan 2 at 9:08

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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