Depositing Cycles from Terminal

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.

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

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

1 Like

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).

1 Like

Thank you very much! That worked like a charm. :grinning:.

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

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

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. @kpeacock Is that expected?

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.

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.

3 Likes

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!

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

2 Likes

Thank you for explaining the details Kyle.

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.

This might help

Yeah might just become a blog or something lol. Thanks

@kpeacock

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.

% 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

% 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

% 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).

% 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 :laughing:

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

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. 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.

5 Likes