Wasm chunking for install_code method

I am following this way, please if you have any better way of doing this, let me know I am a fool :slight_smile:

  1. So I have been writing shell script to first convert a .wasm file to .txt file via wabt tool.
  2. After converting it to text, i decided to chunk the wasm text and then upload it to motoko canister, now challenge I am facing: I am trying to upload text format wasm chunks and motoko only acepts raw text. But wasm text contains special characters and formatted text.

So I think this method is surely not gonna work. If anyone have better way to do install_code from a canister to other canister? Please let me know!!

I’ve done this, but with JS. Basically turned the wasm file in my .dfx into an array. Then pass the array to the canister, stored as blob, then install_code gets the stored blob.

Yes, with js its bit easy.
Did you chunked wasm file?

Yea I had to chunk it, I sent them 1 at a time and appended them to each other in the backend. You may just need to play with the chunk size, the limitation I ran into was an operating system limitation. I’d be curious to know if there was a way to just increase the tolerance for the OS, because it seems in my case its at least within the message size, so it would be nice to do with just an uploadWasm call opposed to 5x uploadWasmChunks calls.

1 Like

Before implementing chunking and stuffs, have you try to just gzip your wasm to see if it goes under 2mb?

If yes, stupid question but why converting to txt file?

1 Like

Interesting, I just added a gzipped wasm and was able to pass in 1 call vs 5, this is super useful.

1 Like

Ah cool, it was a good idea to answer the thread then :smiley:.

For reference, “Large web assembly modules” aka currently gzipping wasm is documented there: https://internetcomputer.org/docs/current/developer-docs/production/larger-wasm/#overview

1 Like

Hey actually i am aware of this method.
But I have a situation where I have multiple child canisters to which i have to install same wasm file, so i guess i will have to use install_code method only via a parent canister(because parent canister is the only controller of child canisters).

So for that i guess i would have to upload whole wasm file to parent canister first and then use it. Am i right? Or is there any other option as well?

That sounds alright, at least matches what I do.

So, if it can help:

Above is a bit old but same in Juno:

Note: in my scripts a chunk is 700kb but, you can probably go up to a bit smaller than 2mb, that should do too.

1 Like

This is exactly what Canister Store do, we using wasm chunks to upload and stored on parent canister, when user click deploy, the function install_code will be called with initial params and wasm data. https://github.com/canister-app/backend.canister.app/blob/master/src/CanisterManager.mo

Thanks for this! I managed to get it done using david examples.

2 Likes

Oh cool, great to hear that!

1 Like