Why are selfdestructs used in contract programming?
I'm reading bits and pieces that selfdestructs within contracts are a good thing. Can someone explain what the benefits are of doing a contract selfdestruct when it comes to Ethereum programming? Is there a difference if you're using different clients or implementations, or languages?
This question is very unclear. Are you asking about contract suicides, or clients or what?
The last sentence is the confusing part, because the go client is a client, solidity is a language, and python could be referring to the python client, or possibly to serpent, the python-like Ethereum language
Selfdestructs in Ethereum are an operation (an OPCODE actually) at the EVM level, independent of what language or client you are using.
For example, calling
selfdestruct(address)sends all of the contract's current balance to
This is useful when you are finished with a contract, because it costs far less gas than just sending the balance with
In fact, the SELFDESTRUCT opcode uses negative gas because the operation frees up space on the blockchain by clearing all of the contract's data.
This negative gas deducts from the total gas cost of the transaction, so if you're doing some clean-up operations first, SELFDESTRUCT can reduce your gas costs.
What happens if you try to call suicided contract? Is it state back to zero or does EVM set some flag telling this contract is no longer here?