How to delete a canister?

I didn‘t want to maintance a canister any more. Any way to delete a useless canister?
How should i do.
And can those cycles remained in the canister return back to to my cycles wallet

2 Likes

dfx canister delete is what you’re looking for
There is no management call to withdraw cycles from a canister yet. Deleting a canister will also discard all of its cycles. For now, you’ll need to install the cycles wallet wasm module onto that canister (or any other canister which supports sending cycles) and transfer them to your destination.

4 Likes

So is it like smart contract in Ethereum?
If i send Ether to a contract without “withdraw” function that can return Ether back to a Ethereum address. i will lost my Ether.

if i creat a canister that doesn’t install cycles wallet wasm module.
all cycles that others send to the canister will be stay in the canister always. and never transfer to other place? No lower-lever interface?

if i creat a canister that doesn’t install cycles wallet wasm module.
all cycles that others send to the canister will be stay in the canister always. and never transfer to other place? No lower-lever interface?

That’s right, no “lower-level interface” just yet. Eventually there should be a management canister interface to withdraw cycles very similar to deposit_cycles

For now try the workaround I mentioned above.

UPDATE: with current dfx, the cycles are automatically returned to the wallet.

This is a summary of the commands and their printed output:

$ dfx --version
dfx 0.8.4

# First stop the canister you want to delete
$ dfx canister --network ic stop <CANISTER_ID>
Stopping code for canister ...

# Now you can delete it
$ dfx canister --network ic delete <CANISTER_ID>
Beginning withdrawl of XXX cycles to canister ...
Setting the controller to identity princpal.
Installing temporary wallet in canister ... to enable transfer of cycles.
Transfering XXX cycles to canister ....
Deleting code for canister ...
5 Likes