Since we have deployed the contract to a relatively congested subnet, we plan to redeploy the contract to a relatively idle subnet before the business is fully started.
Question:
How should we reclaim the cycles in canister before calling IC.delete_canister(xxx) to delete the sub-canister?
When deleting the main canister and want to return its cycles balance, is it correct to use the command and argument dfx canister delete --withdraw-cycles-to-dank main_canister ?
Maybe a scenario makes it easier to discuss. Assume canister A wants to delete canister B but also wants to recover as many cycles as possible. You want to do it roughly this way:
A installs new code to B that knows how to send cycles
Of course you can skip this step if B already has that capability
A instructs B where to send cycles
B uses either ic.deposit_cycles or some other call with attached cycles to transfer as many cycles out as possible
You need to keep a few cycles back to pay for actually making that transfer. If you get an error with the message Call failed to send you most likely added too many cycles.
A can now ic.delete_canister(<B>) with minimal cycles loss