How do cycles work with asset canisters

I have a couple of questions regarding cycle management and asset canisters:

  1. How can i send cycles to an asset canister?
    It seems like I can only create an asset canister with a certain inital cycle balance, but I’m not able to top it up as the method wallet_receive is not available. I found deposit_cycles in the interface spec but I’m not sure if this is the right approach. If so, how would i specify the amount of cycles i want to deposit from the command line?

  2. How are cycles deducted from the asset canisters cycle balance in the wallet UI?
    No matter how often I open the URL where my asset canister is running, I can never observe a deduction of cycles in the wallet UI. I believe this is a bug. dfx canister status shows a reduced amount of cycles correctly.

  3. Why is my wallets cycle balance constantly shrinking?
    I can observe that my cycle balance is constantly shrinking, why is that?
    My guess would be that the wallet canister has to pay for it’s own storage.

  4. How can I “save” cycles from an asset canister I want to delete?

  5. Why does dfx canister status show a Memory allocation and Compute allocation of 0 for an asset canister?

  6. Do we pay for traffic and storage or storage only?

Basically I want to be able to take action and load up a canister with cycles when I see it’s running out of them which currently doesn’t seem to work out of the box for an asset canister.

Tagging @kpeacock @prithvi @nomeata for visibility.


RE 1:
Yes it is, you can use deposit_cycles

dfx canister --network ic call --with-cycles 1000000000000 aaaaa-aa deposit_cycles '(record {canister_id = principal "<canister-principal>"})'

Transactions using this method do not show up in the wallet UI, is this a bug?

Another possible solution if you only have ICPs at hand:

dfx ledger top-up
  1. The command you posted is right, but dfx will have a dfx canister deposit-cycles in the next release to make this easier.
  2. I think the wallet UI only reports its own cycle balance, not of other canisters (asset canisters or otherwise.) Unless that changed in the last release (I haven’t used the UI - but can double check.)
  3. You’re right, the wallet is just like any other canister and has to pay (in cycles) for the resources it consumes.
  4. There’s no management canister method/system api that enables a controller to extract cycles from a canister and deposit them somewhere else. So the developer will have to cook up their own solution to “save” cycles. A stopgap could be to reinstall a wallet wasm (or some other canister which allows cycle sending) onto the target canister. Not nice but that’s what we have for now.
  5. Did you set initialization_values in dfx.json? If not, and you did a dfx deploy both values will be set to None and will show up as 0 when calling canister_status; this is the same for the non assets canister. You can increase the memory/compute allocation via dfx canister update-settings
  6. The official cycle cost documentation is being worked on and should be published soon. I can refer you to that once its out.
1 Like

Many thanks, great answer!

How do those values relate to performance? What changes for my asset canister if I bump those up to the max value?

Both values initally set to zero seems odd, as it implies there is no computing capacity and zero memory available to the canister, but of course it still runs.

You can read about what those settings mean for your canister here: The Internet Computer Interface Specification :: Internet Computer

1 Like

So 0 means unbounded for compute allocation?