How can I call a canister function "--with_cycles"?

Hi,

with SDK version 0.8.3 I was able to call a contract function on a canister “with cycles” like this:

dfx canister call --with-cycles 2000000000000 my_canister function_name "()"

Apparently the “with-cycles” flag does not exist in “canister call” anymore as of version 0.9.3. (dfx canister :: Internet Computer)

So how am I supposed to call my function with cycles from the command line now?

1 Like

Good question, maybe @diegop can escalate this question?

2 Likes

Good question. I have pinged folks. FWIW, i have used --with-cycles in 0.9.3 in a different context (create_canister), so i am surprised it does not work in this context

1 Like

The flag was in 0.9.2, it is still in 0.9.3, and it has never been in the docs, which are a work in progress. In general you should trust the output of <command> --help as the final authority on what commands and flags any given CLI tool supports, including dfx. Any major change, along with how to update your existing workflow to accommodate it if necessary, is also going to be documented in the DFX changelog.

1 Like

It is true that the command is still available in the console. but it does not work anymore as expected if you call a canister with it.

What change are you observing?

If I use the console command to call a function of a canister and use the msg_cycles_available() inside the called canister it always returns 0 on 0.9.3. Prior it returned the sent amount

If you have skipped several versions, and you were not comparing specifically to 0.9.2, then the change you may be observing is that canister commands other than create no longer automatically proxy through the wallet. Wallet proxying is the only way to supply cycles on the command line, as a user principal cannot hold cycles. To replicate the old behavior, you would insert --wallet "$(dfx identity get-wallet)" between canister and call in that command.

3 Likes

The next release of dfx will add an error message instead of letting it silently slide (#2109).

2 Likes

Perfect, makes sense. Thank you for your support. I will test your solution tonight and mark your answer as the solution if everythings works as expected!

1 Like