Cycles as balance before deletion of Canister

Hey guys,
Just wanted to know whats the exact formula to use to calculate the cycles needed to be in a canister before deleting it

The canister needs to be above the freezing threshold to process this call, but there is no other cost. Note that all remaining cycles in the canister’s balance are lost on deletion.

1 Like

so there are 2 canisters A and B. A Is like the manager canister … so before deletion of B I want to return as much cycles possible to canister A . So what is the best way to calculate the maximum cycles I can transfer back to A before B gets deleted ?

The best way is to install a tiny Wasm to B that has just enough functionality to transfer cycles to A. Unfortunately, installing and executing this message will itself use up some cycles, but it can be worth it. You’d also want to lower the freezing threshold of the new tiny-Wasm-B to the minimum.

I believe @mraszyk or @Severin may have shared details about this process before.

1 Like

I accidentally gave a response to the wrong question though. You asked “how to calculate” and I responded to “how to”.

I am not sure how to calculate the max cycles other than with an experiment, because it depends on the size of the least Wasm that has the desired functionality.

1 Like

I like this idea will try it out

1 Like

One could use the new system API ic0.canister_liquid_cycle_balance128 that returns the maximum amount of cycles that can be attached to a call.

1 Like

In dfx we use a hard-coded starting value and then retry with increasing amounts until it works. Since the recent cycles changes the amount is probably too low. I would start with ~80b cycles if I had to just guess today