0

This question already has an answer here:

Is it possible to remove or update already deployed contract using web3 or truffle console or geth console?? if we know the contract details like address and ABI array, and we create a object of contract using web3.js

like var contractObject = web3.eth.contract(abi).at(contractAddress);

then is it possible to remove this contract from block chain using the object created.

I am curious about,Is there any way to call selfDistruct("address") using web3.js??, I have specified contractObject is the object of contract

can I call contractObject.selfDistruct("new address to transfer remaining balance")

the question here explains how to update existing contract but I need a way to remove existing contract even if the contract dose not contain seftDistruct() method.

marked as duplicate by Nicolas Massart, niksmac, Waqar Lim Jun 16 '17 at 9:38

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3

You cannot update a contract at a given address. There are patterns to circumvent this limitation and have upgradable contracts, for example by having a front-end contract at a fixed address that points to the latest version of the contract.

You can invoke a method on the contract that will cause its self destruction, if that method has been implemented at the contract creation and if you meet the requirements - i.e. typically such a method should only accept calls from the owner of the contract. For example, look at the Destructible contract in the open zeppelin library.

You cannot invoke the Solidity selfDistruct opcode directly from web3.js anymore than you can directly change a variable in the contract - you can only interact with a contract through its methods.

1

What @manuhalo said, plus, you might want to consider pausing the contract with a run/stop method and modifier instead of selfDestruct() because the latter creates a sink hole. THe former can throw on all methods and return all funds.

Hope it helps.

1

As @manuhalo said, You can not remove or update a contract from web3 unless your contract is upgradable. Also, to call selfDestruct you need to have a function(preferably with the name - Kill) in your contract, which will have selfDestruct inside the definition, then only you can call it from web3.js


Since this question is related to Upgradable Contracts so I'd like share this with you and hope this help you understand the need and one way of implementing upgradable contracts.

"We(my team) have been working on upgradable contract from past few weeks and we came up with a solution of upgradable contracts after following a blog post from colony.io. We were able to implement the fully upgradeable contract and I'd suggest you to, take a look at the code and blog both"

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