I’ve got a main canister (“manager”) that generates actor class canisters (“data”). In other words, each users of my web app get a canister.
I try to implement the install_code function to be able to upgrade these canisters that are generated on the fly or at least for now, implement a proof of concept of such process.
I have implement it as following:
Instantiate my manager actor with agent-js in a NodeJS script using my private key and actor principal (Code)
Read the wasm file that has been generated with dfx and sent it to my main canister as a blob (Code)
In the main canister, in Motoko, declare a function (that still needs to be access protected but that’s another question) that iterate on each canisters (Code and Code)
In a Motoko utility, effectively call install_code with the Blob data (Code)
When I call my script, I can confirm that the function is effectively triggered and that the user canister is most probably called too (as I get another Principal as the one of my manager in the console output) but, I get the following error anyway:
Error: Call was rejected:
Request ID: 0b96b73711842469a7772d…
Reject code: 4
Reject text: Canister 4wnqn-…-cai trapped explicitly: IDL error: empty input. Expected Candid-encoded argument, but received a zero-length argument
Any idea what am I missing or what is wrong in my implementation ?
Looks like maybe your canister-init function, or your post-upgrade function in your canister takes some candid-parameters. If so, create those candid-parameters, serialize them into the bytes, and put those bytes as the value for the ‘arg’ field.
Yes indeed @levi was correct, it needed a candid-parameter to update the code of the canister because my canister constructor takes a parameter, the user principal.