# Trouble with wasm in install\_code : Management Canister

**URL:** <https://forum.dfinity.org/t/trouble-with-wasm-in-install-code-management-canister/12928>\
**Category:** Developers\
**Tags:** Functional-Programming\
**Created:** [May 12, 2022, 7:42pm UTC](https://forum.dfinity.org/t/trouble-with-wasm-in-install-code-management-canister/12928 "2022-05-12T19:42:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![h1teshtr1path1](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/h1teshtr1path1/32/24662_2.png) [@h1teshtr1path1](https://forum.dfinity.org/u/h1teshtr1path1)\
**Post date:** [May 12, 2022, 7:42pm UTC](https://forum.dfinity.org/t/trouble-with-wasm-in-install-code-management-canister/12928/1 "2022-05-12T19:42:53Z")

</div>

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…

```auto
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!!!

---

<div class="post-metadata">

**Author:** ![skilesare](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/skilesare/32/5609_2.png) [@skilesare](https://forum.dfinity.org/u/skilesare)\
**Post date:** [May 12, 2022, 8:45pm UTC](https://forum.dfinity.org/t/trouble-with-wasm-in-install-code-management-canister/12928/2 "2022-05-12T20:45:09Z")

</div>

You can use DIDC to create the args [Releases · dfinity/candid · GitHub](https://github.com/dfinity/candid/releases).

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

```auto
//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.

---

<div class="post-metadata">

**Author:** ![claudio](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/claudio/32/322_2.png) [@claudio](https://forum.dfinity.org/u/claudio)\
**Post date:** [May 12, 2022, 9:10pm UTC](https://forum.dfinity.org/t/trouble-with-wasm-in-install-code-management-canister/12928/3 "2022-05-12T21:10:30Z")

</div>

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.

> <https://github.com/dfinity/motoko/pull/2010>

> <https://github.com/dfinity/motoko/issues/3199>
>
> Now that we got access to a runtime candid subtype check (#3171), we could consi…der using it to perform a dynamic and atomic (!) type safety check on upgrade. 
> 
> By storing the candid interface in the stable variable blob as an extra type table entry at a known offset (0 springs to mind), the postupgrade method could consult the previous interface stored in stable memory to test compatibility with the new interface, trapping if incompatible.
> 
> That would allow the upgrade to fail and rollback on incompatibility, avoiding the current \[time-of-check/time-of-use hazard \](https://en.wikipedia.org/wiki/Time-of-check\_to\_time-of-use) in the static check implemented by dfx.
> 
> By extending the runtime candid subtype check to deal with \`alias\` idl types (invariant, mutable types) we could also extend the dynamic check to stable variables (we currently omit candid subtype tests when deserializing stable variables, blindly trusting the static check is still valid). The checks could be performed during de-serialization or in bulk prior to deserialization.
> 
> NB: we'd need to rev the stable variable format version to make this work so that we can tell the upgraded canister carries the necessary interface description in type table entry 0.
> 
> A side benefit of this approach is that it would make it easier to type any actor class upgrade facilities, allowing us to rely on the dynamic check instead of enhancing the type system.
> 
> A downside of this approach is that we might want some way to suppress the check for deliberate breaking changes (e.g. during development) or in production (when the canister is perhaps known to have no existing clients.) A compile or prim based run-time flag might suffice for this, causing the postupgrade to abort when the check failed and the flag remains clear.
>  
> @chenyan-dfinity @nomeata @rossberg whaddya think?

---

<div class="post-metadata">

**Author:** ![h1teshtr1path1](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/h1teshtr1path1/32/24662_2.png) [@h1teshtr1path1](https://forum.dfinity.org/u/h1teshtr1path1)\
**Post date:** [May 26, 2022, 6:35am UTC](https://forum.dfinity.org/t/trouble-with-wasm-in-install-code-management-canister/12928/4 "2022-05-26T06:35:53Z")

</div>

One more doubt, while using didc encode ‘(“text”)’

Instead of text , I wanted to pass variable which contains that text, can i do that ? If Yes, Can you please tell me syntax for that , I tried every way, but i am not able to figure out a way !!

didc encode {some variable which contains text value}

---

<div class="post-metadata">

**Author:** ![h1teshtr1path1](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/h1teshtr1path1/32/24662_2.png) [@h1teshtr1path1](https://forum.dfinity.org/u/h1teshtr1path1)\
**Post date:** [May 26, 2022, 6:49am UTC](https://forum.dfinity.org/t/trouble-with-wasm-in-install-code-management-canister/12928/5 "2022-05-26T06:49:20Z")

</div>

Also, can you please provide me some link, how to deal with WASM, Array.data(wasm) is not working I guess. So please if you can elaborate how to deal with wasm. I tried to convert it to text , but not working.
