Trouble with wasm in install_code : Management Canister

Supoose I am having 1000 canisters created using IC management canister with some actor class…
But Later on I need to redeploy those 1000 canisters code with some extra update function, In that case Im supposed to use IC.install_code method for all 1000 canister Ids …
Lets just say I looped over them and will be using install_code method for each canister Id…

await IC.install_code({
                arg = [0] : [Nat8];
                wasm_module = [];
                mode = #upgrade;
                canister_id = cid;
            });

Trouble Im having here is from where to get arg and wasm_module for new Code which i need to deploy… Suppose in some way I can create a .wasm file for new code , then how Im going to change it to

[Blob] or [Nat8] , to get it supported with install_code method…
I found a forum over this, but i didnt get the approach.

Please help with the above method, or you can let me know some more good method if there is one!!!

You can use DIDC to create the args Releases · dfinity/candid · GitHub.

You can read in the wasm as a file and pass it in just like any other blob.

//get arg blob from didc
const ARG_BLOB = Buffer.from('4449444c076c0690......', 'hex')

const ARG_ARR = ARG_BLOB.toJSON().data
const wasmPath = `/canister-3110-6.wasm`;

const data = fs.readFileSync(wasmPath);
 const size = await actor. install_code(ARG_ARR, Array.from(data), {upgrage:null}, canister_id);

I look forward to your cycle burn.

2 Likes

At the moment there is no good way to achieve this from Motoko, I’m afraid.

We have the forthcoming to_candid/from_candid primitives coming soon that will make argument construction easier, but the only install method we have at the moment is a fresh install via the class constructor.

There is a GH PR and issue below that discusses some ways forward but none are that satisfactory.

The solution I currently have in mind is an additional constructor with more install options, coupled with an opt-out dynamic check for interface compatibility during upgrade. Opt-out to allow for deliberate breaking change, when desired.

1 Like