Creating a canister from the frontend

I want to be able to create new canisters directly from the frontend without an intermediate spawn canister on the chain.

I am creating an http agent and using the @dfinity/agent package to obtain a management canister actor.

const httpAgent = await getHttpAgent(identity);
const actor = getManagementCanister({ agent: httpAgent, canisterId: 'qoctq-giaaa-aaaaa-aaaea-cai' });

But when I try to create a new canister like this:

const newCanister = await actor.create_canister({ settings: [] });

I get following error message (the frontend canister is deployed on the test replica when making this call):

Code: 403 (Forbidden)
Body: ic00 method create_canister can be called only by a canister

Is it not possible to do this? or am i missing something?

1 Like

The meaning is that someone has to pay to create the canister. Therefore, this method should be called from the backend of your canister in order to be able to deposit cycles to the new canister.
Try implement canister deployment on the backend and add a method to can.did for the frontend

Thank you. But if this is da DFINITY design decision I don’t really understand it. Afterall, the creation of a canister is just a call of the management canister. And the frontend canister also “owns” cycles. So why would you not be able to call it from a frontend canister?

Solved: you have to use the actor.provisional_create_canister_with_cycles function instead

You don’t need a canister to call agent js, you can do that from the browser or from nodejs, in that case how would you make sure someone is paying the cycles?

When I call
const newCanister = await walletActor.provisional_create_canister_with_cycles({‘settings’: , ‘amount’: [1000000000000000]});

I get
Error: Server returned an error:
Code: 404 (Not Found)
Body:

404 Not Found

404 Not Found


nginx/1.21.3

Any idea?
I am forming wallet actor with
const walletActor = getManagementCanister({ agent: httpAgent, canisterId: ‘<canister_id>’ });

Where canister_id is my wallet canister.

As far as I know, provisional_create_canister_with_cycles is method for local development.
The canister frontend is not a canister, it’s just a website under the canister domain. This is just a reflection of assets from the “backend” asset canister (which called certified-assets - implementation of assets/static storage).
You need to pay for the creation of canisters either from the canister backend itself (then it’s clear where to get cycles from), or you need to implement custom payment through any integrated wallet from frontend.

Okay i understand, thanks for the clarification!

1 Like