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?

1 Answer 1

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.

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

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.