0

I have created the following contract with a destroy function invoking selfdestruct:

pragma solidity >=0.5.0 < 0.7.0;

contract Terminate{
   function destroy() public {
      selfdestruct(msg.sender);
   }
}

$ truffle consoletruffle(development)> 

undefined truffle(development)> T = await Terminate.at('0xA79abEbDb5396053aC4Be4b73282fFef060e410A'); undefined truffle(development)> await T.destroy(); { tx: '0xaaf88fb64a0531d4dd708bbd58908cbf931549519ddbf5e7c5cea40ff30a7bc7',

Now if I try to call 'destroy()', it would be again executed. I thing I must get some error message because I have already destroyed the contract.

truffle(development)> await T.destroy(); { tx:
'0x96166648453aa8653c194e055590849e6bef028ef6017e3e894690b3270f3ff4', receipt: { transactionHash: '0x96166648453aa8653c194e055590849e6bef028ef6017e3e894690b3270f3ff

Why I couldn't destroy the contractusing my earlier call to destroy?

I have stored a copy of the contract in the Github:

> here

Somebody please guide me how to kill the contract using selfdestruct?

Zulfi.

1 Answer 1

2

The first time, it succeeds - silently. No event is emitted, so you would have to check the bytecode length at that addresses to positively confirm that it worked.

The second time, it fails - silently. The effect of "self destruct" is there is no code to raise an error because there is nothing to do. This can create an eery sense that something went wrong. You are expecting something more spectacular.

Here's a little dissertation on selfdestruct that might provide some food for thought. https://blog.b9lab.com/selfdestruct-is-a-bug-9c312d1bb2a5

Hope it helps.

Your Answer

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

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