If token contract 'Bob' has no delegatecalls/ selfdestruct functionality but I transfer the ownership of the contract to contract 'Mallory' and this contract HAS selfdestruct functionality, then the question is, would I be able to terminate/destroy the newly owned contract 'bob' if it's owner is now 'mallory?
Solidity Contract Design – Efficient Self-Destruct Token Contracts
contract-designselfdestructsolidity
Related Solutions
To start my answer, I have to say that once you put something on the blockchain it is "immutable", and by that I mean that it can not be modified or deleted.
(there is a special type of "upgradable" contracts but this is not the answer for that)
You can find here a lot of information about self-destruction.
Why would you need to destroy others? For example, to make a contract not accessible, you can not delete it from the chain but you can disable it.
Can my smart contract destroy a contract owned by another person? This requires a long explanation and has multiple factors at play. But, in summary, no, you can't do it.
How is this destruction implemented? You can use selfdestruct/destroy
(The old mean suicide/kill
). You can find some information here and a good but old tutorial here - the latter explains how this implementation works. Also, here's yet another link with information on the topic.
Do we actually modify previous blocks' contents related to destructed accounts? or we just update the change in the tree structure? We never can modify other blocks, we can only put a new block in the blockchain with more information. Blocks are permanent and they contain the information of the transactions and the contracts. Maybe this can help you with the block concepts.
I have run the code in remix with the according complements for owner and ERC721CrowdSale and your code worked fine. I only slightly modified your contract so that I would get the value of the current owner of the crowdsale returned by the function create_crowdsale(...).
pragma solidity ^0.4.19;
contract Ownable {
address public owner;
function Ownable() public {
owner = msg.sender;
}
modifier onlyOwner {
require(msg.sender == owner);
_;
}
function transferOwnership(address _newOwner) public onlyOwner {
owner = _newOwner;
}
}
contract ERC721CrowdSale is Ownable {
string public name;
address public wallet;
uint256 public token_goal;
function ERC721CrowdSale(string _name, address _wallet, uint256 _token_goal) public {
name = _name;
wallet = _wallet;
token_goal = _token_goal;
}
//...
}
contract CS_Creator is Ownable{
ERC721CrowdSale _cs;
function create_crowdsale(string _name, address _wallet, uint256 _token_goal) onlyOwner returns(address, address){
address _new_crowdsale = new ERC721CrowdSale(_name, _wallet, _token_goal);
transfer_CS_ownership(_new_crowdsale, _wallet);
return (_new_crowdsale, get_CS_ownership(_new_crowdsale));
}
function transfer_CS_ownership(address _new_crowdsale, address _wallet) internal {
_cs = ERC721CrowdSale(_new_crowdsale);
_cs.transferOwnership(_wallet);
}
function get_CS_ownership(address _crowdsale) public returns(address) {
return ERC721CrowdSale(_crowdsale).owner();
}
}
As a return value for the crowdsale owner I get the value for the wallet address.
I could imagine that you actually created a contract ERC721CrowdSale in remix and then were checking there whether the owner address had changed, after deploying CS_Creator. If so: in this case you are creating a new instance of the contract ERC721CrowdSale with the function create_crowdsale(...) which, therefore, is completely independent from the other ERC721CrowdSale contract, you deployed earlyer. The owner address, however, is only changed in the instance, created by the function create_crowdsale(...).
Hope it helps!
Best Answer
No.
selfdestruct
doesn't destroy contracts "owned" by the victim. It may leave orphans that obey no one.As a general rule,
selfdestruct
may be a worse option than pausing all activity. You can add a stop (and unstop) switch. That is more courteous to users and contracts that continue sending ETH to the (destroyed) contract after the point at which it was stopped. In the case ofselfdestruct
, a void is created. The zeroed out contract will accept all ETH sent to it unconditionally and there is no way to recover those funds.