# Depositing Cycles from Terminal

**URL:** <https://forum.dfinity.org/t/depositing-cycles-from-terminal/9438>\
**Category:** Developers\
**Created:** [December 8, 2021, 12:51am UTC](https://forum.dfinity.org/t/depositing-cycles-from-terminal/9438 "2021-12-08T00:51:34Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Motokoder](https://avatars.discourse-cdn.com/v4/letter/m/e47c2d/32.png) [@Motokoder](https://forum.dfinity.org/u/Motokoder)\
**Post date:** [December 8, 2021, 12:51am UTC](https://forum.dfinity.org/t/depositing-cycles-from-terminal/9438/1 "2021-12-08T00:51:34Z")

</div>

I am trying to add cycles to a Mainnet canister from my terminal. I have 15T cycles in my default wallet from the Fleek faucet. I know the cycles wallet is working correctly because my network calls are executing and returning a response.

When the deposit\_cycles sub command fails, it shows my dfx principal listed as a controller for the canister but states that only the controllers can access it.

I am running the command with the correct principal and I have a cycles wallet with 15T cycles in it. So can someone help me understand why the command is failing? Thank you.

```auto
dfx --version
dfx 0.8.4

dfx identity get-principal
6iphn-47gfi-w76ag-lbs4x-dur3m-v2zdl-cwekw-kce2v-gvluy-fqgeo-sqe

dfx canister --network ic id mycanister
u33e2-gyaaa-aaaai-qa3vq-cai

dfx canister --network ic deposit-cycles 1000000000000 mycanister
Depositing 1000000000000 cycles onto mycanister
The invocation to the wallet call forward method failed with the error:
An error happened during the call: 5: Only the controllers of the canister u33e2-gyaaa-aaaai-qa3vq-cai can control it.
Canister's controllers: ssxn6-sow66-3zjk3-nmzdl-7ezmn-kwtgw-zcrpa-jsqoa-yttdm-l7dyi-aqe 6iphn-47gfi-w76ag-lbs4x-dur3m-v2zdl-cwekw-kce2v-gvluy-fqgeo-sqe
Sender's ID: nhift-miaaa-aaaai-aa72a-cai

```

---

<div class="post-metadata">

**Author:** ![anon74414410](https://avatars.discourse-cdn.com/v4/letter/a/85f322/32.png) [@anon74414410](https://forum.dfinity.org/u/anon74414410)\
**Post date:** [December 8, 2021, 1:18am UTC](https://forum.dfinity.org/t/depositing-cycles-from-terminal/9438/2 "2021-12-08T01:18:51Z")

</div>

I’ll take a look tomorrow if no one has solved it before then!

---

<div class="post-metadata">

**Author:** ![GLdev](https://avatars.discourse-cdn.com/v4/letter/g/4bbf92/32.png) [@GLdev](https://forum.dfinity.org/u/GLdev)\
**Post date:** [December 8, 2021, 8:46am UTC](https://forum.dfinity.org/t/depositing-cycles-from-terminal/9438/3 "2021-12-08T08:46:15Z")

</div>

> [@Motokoder](#):
>
> ```auto
> Canister's controllers: ssxn6-sow66-3zjk3-nmzdl-7ezmn-kwtgw-zcrpa-jsqoa-yttdm-l7dyi-aqe 6iphn-47gfi-w76ag-lbs4x-dur3m-v2zdl-cwekw-kce2v-gvluy-fqgeo-sqe
> Sender's ID: nhift-miaaa-aaaai-aa72a-cai
> 
> ```

Is your cycles wallet nhift-… ? In that case the call might be routed through it, but that canister’s ID is not a controller of your u33e2… canister. If nhift is really your cycles\_canister, try adding it as a controller to your other canister (I believe you run --no-wallet commands from dfx to go straight to your canister, and the call will come from your 6iphn- principal).

---

<div class="post-metadata">

**Author:** ![Motokoder](https://avatars.discourse-cdn.com/v4/letter/m/e47c2d/32.png) [@Motokoder](https://forum.dfinity.org/u/Motokoder)\
**Post date:** [December 8, 2021, 12:04pm UTC](https://forum.dfinity.org/t/depositing-cycles-from-terminal/9438/4 "2021-12-08T12:04:42Z")

</div>

Thank you very much! That worked like a charm. 😀.

I had no idea that the cycles wallet had to be a controller as well.

```auto
dfx canister --network ic deposit-cycles 1000000000000 mycanister
Depositing 1000000000000 cycles onto mycanister
Deposited 1000000000000 cycles, updated balance: 7_884_073_390_539 cycles

```

---

<div class="post-metadata">

**Author:** ![Motokoder](https://avatars.discourse-cdn.com/v4/letter/m/e47c2d/32.png) [@Motokoder](https://forum.dfinity.org/u/Motokoder)\
**Post date:** [December 8, 2021, 12:19pm UTC](https://forum.dfinity.org/t/depositing-cycles-from-terminal/9438/5 "2021-12-08T12:19:00Z")

</div>

Interesting. I just tried sending cycles to my other canister that did not have the cycles wallet added to controllers. It gave me the same error message, but the cycles were taken from the wallet and added to the canister. I verified in NNS. @anon74414410 Is that expected?

```auto
dfx wallet --network ic balance
8899293921278 cycles.

dfx canister --network ic deposit-cycles 2000000000000 mycanister       
Depositing 2000000000000 cycles onto mycanister
The invocation to the wallet call forward method failed with the error: An error happened during the call: 5: Only the controllers of the canister visab-xyaaa-aaaal-qaaoa-cai can control it.
Canister's controllers: ssxn6-sow66-3zjk3-nmzdl-7ezmn-kwtgw-zcrpa-jsqoa-yttdm-l7dyi-aqe 6iphn-47gfi-w76ag-lbs4x-dur3m-v2zdl-cwekw-kce2v-gvluy-fqgeo-sqe
Sender's ID: nhift-miaaa-aaaai-aa72a-cai

dfx wallet --network ic balance                             
6899287429613 cycles.

```

---

<div class="post-metadata">

**Author:** ![nomeata](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/nomeata/32/733_2.png) [@nomeata](https://forum.dfinity.org/u/nomeata)\
**Post date:** [December 8, 2021, 2:13pm UTC](https://forum.dfinity.org/t/depositing-cycles-from-terminal/9438/6 "2021-12-08T14:13:07Z")

</div>

It’s probably because `dfx` is doing more in that command invocation, such as checking the cycle balance. So the deposit works, but then reading the cycle balance fails, and `dfx` does not handle that gracefully.

---

<div class="post-metadata">

**Author:** ![Motokoder](https://avatars.discourse-cdn.com/v4/letter/m/e47c2d/32.png) [@Motokoder](https://forum.dfinity.org/u/Motokoder)\
**Post date:** [December 8, 2021, 3:21pm UTC](https://forum.dfinity.org/t/depositing-cycles-from-terminal/9438/7 "2021-12-08T15:21:57Z")

</div>

Thanks. That makes sense now. It would seem that the read operation should be successful since the command is executed by a principal that is a controller. If the cycle wallet does not have read permission, I would expect it to be overridden by the principal’s permissions. However, the IC may do things differently, so I probably need to focus my studies in that area. I really appreciate your response!

---

<div class="post-metadata">

**Author:** ![anon74414410](https://avatars.discourse-cdn.com/v4/letter/a/85f322/32.png) [@anon74414410](https://forum.dfinity.org/u/anon74414410)\
**Post date:** [December 8, 2021, 5:33pm UTC](https://forum.dfinity.org/t/depositing-cycles-from-terminal/9438/8 "2021-12-08T17:33:52Z")

</div>

Yeah, I think that @nomeata is correct. Reading a cycles balance is a permissioned query, but transferring cycles is always allowed, at a protocol level. The output from `dfx` should be improved to indicate that the cycles transfer took place, but that `dfx` was unable to verify the new balance of the destination canister

---

<div class="post-metadata">

**Author:** ![Motokoder](https://avatars.discourse-cdn.com/v4/letter/m/e47c2d/32.png) [@Motokoder](https://forum.dfinity.org/u/Motokoder)\
**Post date:** [December 8, 2021, 6:15pm UTC](https://forum.dfinity.org/t/depositing-cycles-from-terminal/9438/9 "2021-12-08T18:15:12Z")

</div>

Thank you for explaining the details Kyle.

---

<div class="post-metadata">

**Author:** ![cyberowl](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/cyberowl/32/3635_2.png) [@cyberowl](https://forum.dfinity.org/u/cyberowl)\
**Post date:** [December 14, 2021, 12:45pm UTC](https://forum.dfinity.org/t/depositing-cycles-from-terminal/9438/10 "2021-12-14T12:45:22Z")

</div>

I created some canisters from the NNS that I want to decommission and move the cycles to canisters I created via `dfx`. Is the only way currently to add methods to those canisters to transfer the cycles or is there a function that will allow that to happen in the future.

---

<div class="post-metadata">

**Author:** ![saikatdas0790](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/saikatdas0790/32/17147_2.png) [@saikatdas0790](https://forum.dfinity.org/u/saikatdas0790)\
**Post date:** [December 17, 2021, 7:53am UTC](https://forum.dfinity.org/t/depositing-cycles-from-terminal/9438/11 "2021-12-17T07:53:50Z")

</div>

This might help

> [@How to collect the cycles from the useless canisters?](https://forum.dfinity.org/t/how-to-collect-the-cycles-from-the-useless-canisters/8150/4):
>
> I would suggest not destroying the canister but reusing it to deploy whatever new wasm you’re deploying. That way the 1T cycles used when creating a new canister is not wasted. Simply use the same identity and the existing canister ID in your new project’s canister\_ids.json when deploying.

---

<div class="post-metadata">

**Author:** ![cyberowl](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/cyberowl/32/3635_2.png) [@cyberowl](https://forum.dfinity.org/u/cyberowl)\
**Post date:** [December 17, 2021, 9:54am UTC](https://forum.dfinity.org/t/depositing-cycles-from-terminal/9438/12 "2021-12-17T09:54:51Z")

</div>

Yeah might just become a blog or something lol. Thanks

---

<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:** [May 12, 2022, 10:02pm UTC](https://forum.dfinity.org/t/depositing-cycles-from-terminal/9438/13 "2022-05-12T22:02:34Z")

</div>

@anon74414410

Ran into some issues when topping up a canister running in my **local environment**. Here’s a rambling of me trying to get it to work.

```auto
% dfx canister deposit-cycles 20000000000000 t6rzw-2iaaa-aaaaa-aaama-cai
Error: The deposit cycles call needs to proxied via the wallet canister. Invoke this command without the `--no-wallet` flag.

```

ok

```auto
% dfx canister deposit-cycles --no-wallet 20000000000000 t6rzw-2iaaa-aaaaa-aaama-cai
error: Found argument '--no-wallet' which wasn't expected, or isn't valid in this context

        If you tried to supply `--no-wallet` as a value rather than a flag, use `-- --no-wallet`

USAGE:
    dfx canister deposit-cycles [OPTIONS] <CYCLES> [CANISTER]

For more information try --help

```

A few more naive tries

```auto
% dfx canister deposit-cycles 20000000000000 t6rzw-2iaaa-aaaaa-aaama-cai -- --no-wallet   
error: Found argument '--no-wallet' which wasn't expected, or isn't valid in this context

        If you tried to supply `--no-wallet` as a value rather than a flag, use `-- --no-wallet`

USAGE:
    dfx canister deposit-cycles [OPTIONS] <CYCLES> [CANISTER]

For more information try --help
% dfx canister deposit-cycles 20000000000000 t6rzw-2iaaa-aaaaa-aaama-cai `-- --no-wallet`
zsh: command not found: --
Error: The deposit cycles call needs to proxied via the wallet canister. Invoke this command without the `--no-wallet` flag.

```

Hmm, that’s where we were originally - I’ll try to specify a wallet name to use (the one I’m using by default).

```auto
% dfx wallet set-name local
% dfx canister deposit-cycles --wallet=local 20000000000000 t6rzw-2iaaa-aaaaa-aaama-cai
error: Found argument '--wallet' which wasn't expected, or isn't valid in this context

        Did you mean '--all'?

        If you tried to supply `--wallet` as a value rather than a flag, use `-- --wallet`

USAGE:
    dfx canister deposit-cycles --all <CYCLES>

For more information try --help

% dfx canister deposit-cycles --all 20000000000000
Error: The deposit cycles call needs to proxied via the wallet canister. Invoke this command without the `--no-wallet` flag.

```

Ok, I’m confused now, time for the forums 😆

Do I need to create a wallet canister? I thought that came bundled and abstracted away with dfx?

---

<div class="post-metadata">

**Author:** ![Vivienne](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/vivienne/32/29170_2.png) [@Vivienne](https://forum.dfinity.org/u/Vivienne)\
**Post date:** [May 13, 2022, 7:57am UTC](https://forum.dfinity.org/t/depositing-cycles-from-terminal/9438/14 "2022-05-13T07:57:25Z")

</div>

> [@icme](#):
>
> Ok, I’m confused now, time for the forums 😆

Totally understandable…

First off, since you’re running on a local environment: If you’re on dfx 0.10.0, `dfx ledger fabricate-cycles` is meant for that very situation. Anyways, you asked about `deposit-cycles`.

The error message is bad/outdated. I’ll update it in [this PR](https://github.com/dfinity/sdk/pull/2201). The new error message will be `The deposit cycles call needs to proxied via the wallet canister. Please run this command using 'dfx canister --wallet <your wallet id> deposit-cycles <other arguments>'.`

If you look closely, you put the wallet flag as part of the `deposit-cycles` subcommand, and not as part of the `canister` command. dfx does expect it to be `dfx canister --wallet <your wallet>` and only AFTER that the `deposit-cycles <other args>`.

dfx _should_ accept the wallet flag anywhere, no question. I’ll note it in our backlog.
