# How to retrieve cycles from an abandoned canister

**URL:** <https://forum.dfinity.org/t/how-to-retrieve-cycles-from-an-abandoned-canister/7022>\
**Category:** Community Tutorials & Video\
**Created:** [September 5, 2021, 5:29pm UTC](https://forum.dfinity.org/t/how-to-retrieve-cycles-from-an-abandoned-canister/7022 "2021-09-05T17:29:45Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![cryptoschindler](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/cryptoschindler/32/26_2.png) [@cryptoschindler](https://forum.dfinity.org/u/cryptoschindler)\
**Post date:** [September 5, 2021, 5:29pm UTC](https://forum.dfinity.org/t/how-to-retrieve-cycles-from-an-abandoned-canister/7022/1 "2021-09-05T17:29:45Z")

</div>

Note that this guide uses dfx version `0.8.1`

1. Create a new identity using

```auto
dfx identity new move_cycles

```

1. Use the identity created by issuing

```auto
dfx identity use move_cycles

```

1. Save the principal ID of the `move_cycles` identity to the environment variable `MOVE_CYCLES_IDENTITY` by running

```auto
MOVE_CYCLES_IDENTITY=$(dfx identity get-principal)

```

1. Use the previous identity that is controller of the wallet canister that controls the abandoned canister by issuing the following command and substituting `<your_old_identity>` accordingly

```auto
dfx identity use <your_old_identity>

```

1. Make the `move_cycles` identity the controller of the abandoned canister.  
Make sure you run this command from within a dfx project folder and edit the `canister_ids.json` file so that the canister id of the abandoned canister is present. If your `canister_ids.json` file contains those entries,

```auto
{
  "assets": {
    "ic": "kwflp-viaaa-aaaae-aaaaa-cai"
  },
  "kanban": {
    "ic": "kren3-yqaaa-aaaae-aaaaa-cai"
  }
}

```

replace one of the canister ids with the id of the abandoned canister like this

```auto
{
  "assets": {
    "ic": "<abandoned_canister_id>"
  },
  "kanban": {
    "ic": "kren3-yqaaa-aaaae-aaaaa-cai"
  }
}

```

Then run

```auto
dfx canister --network ic update-settings --controller $MOVE_CYCLES_IDENTITY <abandoned_canister_id>

```

1. Now that the `move_cycles` identity is the controller of the abandoned canister, switch back to it by issuing

```auto
dfx identity use move_cycles

```

1. Run the following command to uninstall the canister

```auto
dfx canister --network ic --no-wallet uninstall-code <abandoned_canister_id>

```

1. Now run the following command to deploy a cycles wallet to the now empty canister

```auto
dfx identity --network ic deploy-wallet <abandoned_canister_id>

```

1. Finally you can either send cycles to the cycles wallet of your main identity by issuing the following command or accesing the cycles wallet frontend under `<abandoned_canister_id>.ic0.app` and following the instructions on screen

```auto
dfx wallet --network ic send <main_cycles_wallet_id> <amount_of_cycles_to_send>

```

1. If you want to you can now stop the wallet canister **after** you moved the cycles by running

```auto
dfx canister --network ic stop <abandoned_canister_id>

```

and

```auto
dfx canister --network ic delete <abandoned_canister_id>

```

1. If you no longer need the `move_cycles` identity you can also remove it by issuing

```auto
dfx idenity remove move_cycles

```

---

<div class="post-metadata">

**Author:** ![goose](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/goose/32/6164_2.png) [@goose](https://forum.dfinity.org/u/goose)\
**Post date:** [September 24, 2021, 9:35am UTC](https://forum.dfinity.org/t/how-to-retrieve-cycles-from-an-abandoned-canister/7022/2 "2021-09-24T09:35:49Z")

</div>

dfx canister --network ic --no-wallet uninstall-code XXXXXXXXXX  
the replica returned an HTTP Error: Http Error: status 403 Forbidden, content type “”, content: Requested canister rejected the message， why??

---

<div class="post-metadata">

**Author:** ![cryptoschindler](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/cryptoschindler/32/26_2.png) [@cryptoschindler](https://forum.dfinity.org/u/cryptoschindler)\
**Post date:** [September 24, 2021, 2:33pm UTC](https://forum.dfinity.org/t/how-to-retrieve-cycles-from-an-abandoned-canister/7022/3 "2021-09-24T14:33:14Z")

</div>

Did you make sure you changed your dfx identity as described in step 6?

---

<div class="post-metadata">

**Author:** ![0xlup3x](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/0xlup3x/32/5816_2.png) [@0xlup3x](https://forum.dfinity.org/u/0xlup3x)\
**Post date:** [June 26, 2022, 11:14am UTC](https://forum.dfinity.org/t/how-to-retrieve-cycles-from-an-abandoned-canister/7022/4 "2022-06-26T11:14:39Z")

</div>

Is this still applicable? Seems rather complicate to take back some cycles from a canister.

---

<div class="post-metadata">

**Author:** ![cryptoschindler](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/cryptoschindler/32/26_2.png) [@cryptoschindler](https://forum.dfinity.org/u/cryptoschindler)\
**Post date:** [July 1, 2022, 1:54pm UTC](https://forum.dfinity.org/t/how-to-retrieve-cycles-from-an-abandoned-canister/7022/5 "2022-07-01T13:54:20Z")

</div>

no, you can now simply run  
`dfx canister --network ic stop <canister id>`  
and then  
`dfx canister --network ic delete <canister id>`

---

<div class="post-metadata">

**Author:** ![bob11](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/bob11/32/1979_2.png) [@bob11](https://forum.dfinity.org/u/bob11)\
**Post date:** [December 31, 2022, 7:00pm UTC](https://forum.dfinity.org/t/how-to-retrieve-cycles-from-an-abandoned-canister/7022/6 "2022-12-31T19:00:44Z")

</div>

If you have a canister controlling another canister (and you use cross-canister calls to create, manage, and delete child canisters) can you still just stop and delete a child canister to get the cycles back? I’m assuming perhaps not?

---

<div class="post-metadata">

**Author:** ![icme](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/icme/32/4327_2.png) [@icme](https://forum.dfinity.org/u/icme)\
**Post date:** [December 31, 2022, 7:55pm UTC](https://forum.dfinity.org/t/how-to-retrieve-cycles-from-an-abandoned-canister/7022/7 "2022-12-31T19:55:11Z")

</div>

You need to first have a method on the child canister that calls `deposit_cycles` and deposits the cycles back into the parent canister.

Then you can stop/delete the canister after.

---

<div class="post-metadata">

**Author:** ![bob11](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/bob11/32/1979_2.png) [@bob11](https://forum.dfinity.org/u/bob11)\
**Post date:** [January 1, 2023, 2:52am UTC](https://forum.dfinity.org/t/how-to-retrieve-cycles-from-an-abandoned-canister/7022/8 "2023-01-01T02:52:28Z")

</div>

Yeah, I assumed I would need to manually send the cycles back first, but it would be nice if you could “delete\_and\_reclaim\_cycles” in a single command. Not the end of the world though.

Thanks!
