EOSIO / eos

An open source smart contract platform
https://developers.eos.io/manuals/eos
MIT License
11.27k stars 3.6k forks source link

How to remove(delete / replace) a contract ? #1384

Closed swdevMPaul closed 6 years ago

swdevMPaul commented 6 years ago

Hi,

Does anyone know which command to execute in order to delete previously published(uploaded) contract ?

Kind Regards,

Paul.

sim31 commented 6 years ago

To replace code you can just use the same cleos command you used to upload code. To delete code - upload wast and abi files which does nothing? To free RAM your contract uses, the only way I'm aware of is to do it from contract itself (add an action in your contract which deletes all the rows in all of the tables). Maybe someone else can suggest a better way of doing these things?

andriantolie commented 6 years ago

Yes, to replace just use the same command you use to upload the contract. I don't think there's a way to delete the uploaded contract but you can always replace it with a contract that does nothing.

xJonathanLEI commented 6 years ago

With eosjs, the following code should do the trick:

eos.setcode(account_name, 0, 0, new Uint8Array());
xJonathanLEI commented 6 years ago

Setting the code to an empty byte array also changes code hash to 0. It's a much better solution than replacing it with a contract that does nothing, as such a contract still takes up RAM space and thus EOS.

jjgonecrypto commented 5 years ago

@xJonathanLEI What would happen to any tables that were already in use for that contract? Would they be orphaned yet still cost RAM? Should you first empty the tables out?

jjgonecrypto commented 5 years ago

Update: according to @michaeljyeates on Telegram, you should first empty any tables out before setting the wasm code to an empty array.