Rust ic_cdk: How to specify cycle_amount to transfer when creating canister using `create_canister`

How do I specify the amount of cycles to transfer when creating a canister using ic_cdk’s create_canister method?

When running this on the local replica, 1T cycles is used and 0.9T is added to the created canister’s balance and 0.1T is consumed for creation.

  • Is the behaviour same on mainnet?
  • How can I provision a canister using less than 1T from the provisioning canister?
1 Like

Hi @saikatdas0790,

I just made a PR to fix the problem: feat: specify cycles when create canister by lwshang · Pull Request #322 · dfinity/cdk-rs · GitHub

I fixed the cycles cost to create_canister which should be 0.1T instead of 1T.
And I added another method create_canister_with_extra_cycles so that you can specify extra cycles to the new canister.

Update: The PR was merged and ic-cdk v0.6.2 got published.

3 Likes

That’s sort of an deceptive API to have ( create_canister_with_extra_cycles), in that if one specifies 1T cycles, it actually spends 1.1T cycles (100 billion burned for canister creation).

It also seems like create_canister_with_extra_cycles will become preferred by developers and should be the default API used, since it would reduce the number of steps taken in spinning up and funding a new canister.

This seems like a backwards-incompatible change to create_canister - won’t this break existing applications that are dynamically spinning up canisters, since after this change the newly spun up canister won’t have any cycles left over afterwards? (requires manual intervention and additional top-up step, as opposed to previously expecting the canister to have 0.9T cycles left over).

I think it’s fine if it’s documented well. As documented here and here

This entire change is part of ic_cdk > 0.6 onwards so devs would check the changelog before randomly upgrading so I think it’s fine.

create_canister_with_extra cycles is just create_canister combined with deposit_cycles as seen in the source

create_canister_with_extra cycles

image

create_canister

deposit_cycles