0

Hey I'm trying to use selfdestruct in solidity but I'm getting this error when I'm trying to run selfdestruct(address*) :

TypeError: Invalid type for argument in function call. Invalid implicit conversion from int_const 0 to address payable requested. --> contracts/Hello_World.sol:9:22: | 9 | selfdestruct(0x0); | ^^^

*address- my Ethereum address

The code :

pragma solidity >=0.7.0 <0.9.0; 
contract HelloWorld { 
string public message; 
function setMessage(string memory newMessage) public { 
message = newMessage; 
} 

function remove() public {
 selfdestruct(0x0); 
} 
}
2
  • Can you post more code? That error doesn't sound like it's related to selfdestruct.
    – bru53001
    Jun 29 at 18:56
  • Hi MicahTaylor! Welcome to Ethereum Stackexchange! It is better to edit your own question to add a code, since in the comments it is not formatted and hard to read.
    – Ismael
    Jun 30 at 1:20
0

Apparently you're passing a constant integer to selfdestruct, while the correct call would be to pass an address. 0x0 is not the 0 address, it's just the hexadecimal form of the integer 0. You need to convert it into a payable address and pass it to selfdestruct as follows:

selfdestruct(payable(0x0))

Actually, you don't even need to use the hex format and you could just use the decimal format as follows:

selfdestruct(payable(0))

Note: casting as payable only works in Solidity versions >=0.6.0.

By the way, what this call does is burn any ETH contained in that contract upon destruction. Make sure that this is what you want to do.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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