Read local file at build time with Motoko

Is it possible in Motoko to read a local file at build time? More precisely, is it possible to read the wasm file of another canister as Blob?


Context:

I try to create canister on the fly (“child canister”) written in Rust from Motoko. I have a working solution but it implies creating the “child canister” from a Rust canister, that’s why I would like to spare that middle step and directly create these from Motoko

Current solution: Motoko canister call → Rust canister which creates → Rust child canister
Wish solution: Motoko canister creates → Rust child canister

(sample repo)

You just upload the wasm into a blob-based store and then implement the nns did file so that you can call the deploy canister function and pass in the bits.

1 Like

Thanks, did not though about it, that’s indeed an interesting option!

I could also add a script that reads the wasm and just drop the bytes in a .mo file which is then used in my actor but, if I can spare some tooling and solve this directly in Motoko that would be for the best.

I try to read and inject a .mo file for the wasm but of course then the compiler will fails because it cannot handle so much memory. Likewise there is no feature to read a file from Motoko so the only way is your solution. Thanks for your share.

1 Like