Reading wasm module blob in Nodejs

Hi all, I faced the same issue as above when passing the parameters for install_code method to upgrade canisters using NodeJs.

let updateSubCanisters = async () => {
    const wasm = fs.readFileSync("./../../.dfx/local/canisters/testaudit/testaudit.wasm")
   // const args = Array.from(IDL.encode([IDL.Text], ["Xep"])); <---- instead of Array use Uint8Array as below
    const args = [... new Uint8Array(IDL.encode([IDL.Text], ["Xep"]))];
    console.log(args)
    const res = await testaudit.upgradesub(
  [...new Uint8Array(wasm)], 
  args
).catch(e => { return "Error" + e });
    return res;
}

The problem here is that a simple array is treated as Candid [Nat8] and Uint8Array is treated as a Candid Blob data type respectively.

2 Likes