Greetings everyone! In an instance where a canister would create another canister in mainnet. I always get an issue that there are not enough cycles to create a canister. With this issue how could I create a canister multiple times. An example would be the code below.
Canister A creating Canister B
try {
Cycles.add(1_500_000_000_000);
let newDirectoryActor = await ConsumerDirectoryClass.ConsumerDirectory();
let directoryActorId : Principal = await newDirectoryActor.consumerDirectory_getCanisterId();
let adminCanister : Principal = await AdminApp.admin_getPrincipal();
await ICUTIL.updateCanisterSettings(directoryActorId, [adminAccount, adminCanister, Principal.fromActor(ConsumerApp)]);
await ICUTIL.depositCycles(Principal.fromActor(ConsumerApp));
await AdminApp.admin_createCanister(directoryActorId, #consumerDirect);
Debug.print(debug_show(directoryActorId));
consumer_directoryCount := consumer_directoryCount + 1;
listOfConsumerDirectory := List.push<ConsumerDirectoryClass.ConsumerDirectory>(newDirectoryActor, listOfConsumerDirectory);
} catch (e) {
return #err(Error.message(e));
};
Canister B will try to create Canister C but it fails
try {
Cycles.add(150_000_000_000);
let newConsumerActor = await ConsumerActorClass.ConsumerDatabase(consumerId, firstName, lastName, birthday, country, email, profilePicture);
let newConsumerId : CanisterId = await newConsumerActor.consumer_getCanisterId();
let adminCanister : Principal = await AdminApp.admin_getPrincipal();
await ICUTIL.updateCanisterSettings(newConsumerId, [adminCanister, adminAccount, Principal.fromActor(cannister_self)]);
await ICUTIL.depositCycles(Principal.fromActor(cannister_self));
await AdminApp.admin_createCanister(newConsumerId, #consumerData);
mapOfConsumer.put(consumerId, newConsumerActor);
Debug.print(debug_show (newConsumerId));
return #ok(newConsumerId);
} catch (e) {
return #err(Error.message(e));
};
Is there a way for canister C to be created, I place 2T cycles already and based on computation in “Cycles.add” it is already enough to create a couple of canister C. Thank you very much!