How to add cycles on canister creation?

How to add cycles on canister creation (constructor call by Motoko)?

ChatGPT claims “Motoko, the programming language for the DFINITY Internet Computer, does not provide a direct mechanism within the code to add or allocate cycles during the creation of a canister.”

To function calls cycles are added by pairing Cycles.add and Cycles.accept. But, apparently, Cycles.accept can’t be run from actor creation code. So, how to do this?

Accordingly ChatGPT, “As of my last knowledge update in September 2021, when you create a new canister on the DFINITY Internet Computer using Motoko code, the amount of cycles allocated to the canister is determined by the settings provided in your deployment configuration. This configuration is typically specified using the DFX (Dfinity eXtended) tool or the Internet Computer’s governance system, and it’s not directly controlled within the Motoko code.”

So, if the canister is not presented in dfx.json, but is created directly from Motoko code, how is the amount of cycles allocated determined?

IIRC you just call Cycles.add() before calling the class constructor. These cycles don’t need be accepted explicitly, and are just added to the new canister.

There is an example here: