Blockchain & Cryptocurrency Glossary

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

  • search-icon Clear Definitions
  • search-icon Practical
  • search-icon Technical
  • search-icon Related Terms

SelfDestruct

1 min read
Pronunciation
[self di-struhkt]
Analogy
Imagine a self-demolishing building. The `SelfDestruct` opcode is like pushing the demolition button for a smart contract. The contract's structure (code) and contents (storage) are wiped from the active records, and any remaining funds (Ether) are transferred to a pre-specified recipient.
Definition
An opcode (operation code) in some smart contract platforms (notably Ethereum) that allows a contract to remove its own code and storage from the blockchain state, sending any remaining Ether in its balance to a designated address. This operation is generally discouraged due to its potential risks and impact.
Key Points Intro
SelfDestruct is an Ethereum opcode that removes a contract from the blockchain.
Key Points

Removes the contract's bytecode and storage from the state.

Transfers the contract's entire Ether balance to a specified target address.

It's a permanent action; the contract cannot be restored.

Historically used as a way to upgrade contracts (by destroying the old one and deploying a new one) or to recover locked funds in emergencies.

Its use is now heavily discouraged due to security implications (e.g., Ether being forcibly sent to contracts that might not expect it) and the availability of better upgrade patterns.

Example
A developer might have included a `selfdestruct(owner_address)` function in an early version of a contract to allow them to remove it if a critical bug was found. Calling this function would erase the contract and send its ETH balance to `owner_address`.
Technical Deep Dive
The `SELFDESTRUCT` opcode (0xFF in EVM) takes one argument from the stack: the address to send the remaining Ether. After its execution, subsequent calls to the contract address will find no code. While it clears storage, it doesn't erase the historical transaction data related to the contract on the blockchain. EIP-4758 proposes to deactivate SELFDESTRUCT, and its functionality is being phased out or modified in Ethereum updates.
Security Warning
Using `SelfDestruct` can be dangerous. It can lead to accidental loss of funds if the target address is incorrect or if Ether is forcibly sent to contracts not designed to receive it. It can also be a vector for certain types of attacks if not handled carefully. Modern upgrade patterns (like proxies) are preferred.

SelfDestruct - Related Articles

No related articles for this term.