I read the Contract's state after a selfdestruct thread, but it doesn't answer the question whether you can selfdestruct multiple times.
2 Answers
It may depend on what your definition of "contract" is. :-)
Once a contract is selfdestructed, there is no code at that address anymore, so it can't execute a SELFDESTRUCT again.
However, due to the existence of CREATE2, you can now potentially deploy new code to the same address as the previous contract. That new code could contain a SELFDESTRUCT opcode. This means that the same address can run a SELFDESTRUCT multiple times, but whether it's really the same "contract" or not is a question of how you define that term.
- 27,999
- 2
- 30
- 48
Update
As per Steven's comment below, you *cannot* sefldestruct more than once because no SELFDESTRUCT opcode will be executed again (there's no code at that address anymore).
Yes, you can, with a few caveats:
- During the first selfdestruct, the state of the contract is erased and will remain like that forever. You will be able to call the methods without reverting though.
- The Ether balance will only get depleted the first time.
Let's see it in action:
pragma solidity 0.5.11;
contract Counter {
uint256 public counter;
function increment() external {
counter = counter + 1;
}
function doSelfDestruct() external {
selfdestruct(0x0000000000000000000000000000000000000000);
}
function() external payable {}
}
Steps:
- Deploy the contract on Remix.
- Call
increment. - Read
counter. Should be 1. - Transfer Ether to the contract (set around 30,000 gas).
- Call
doSelfDestruct. - The Ether balance and its state should both be gone.
- Call
incrementagain. - Read
counter. Should be 0. - Repeat steps #3 and #4. The balance should not be transferred again.
- 17,902
- 6
- 73
- 143
doSelfDestruct(), no actualSELFDESTRUCTopcode execute. You can send whatever data you want to the contract address, but because there's no longer any code, no code will be executed. – user19510 Sep 21 '19 at 21:21