I am trying to take the build output of a dfx build
step which is a canister wasm file and trying to pass it as an argument to another canister via dfx canister call
.
I imagine it has to be the blob
type as documented here since I’m accepting Vec<u8>
on the Rust parameter side.
Thoughts on how I would achieve this? What would the dfx canister call
look like?
Hi @saikatdas0790
We have a script for that in Internet Identity, because it is indeed quite cumbersome to do manually. See here: https://github.com/dfinity/internet-identity/blob/6c80aa0e30162d1aa09fb7348cbd6e4469cd1836/scripts/deploy-archive#L96
You have to read the wasm as binary, hex encode it and then add \
before hex encoded every byte and give that to dfx
as a string…
I have a ticket open with the SDK team, to make this more convenient out of the box.
4 Likes
Hi @frederikrothenberger,
Quick follow up question. Do you know of an easy way to generate the hash of the wasm on the command line?
My end game with this is to query the dfx canister info
and get the running canister wasm and then compare that with the wasm that I’m passing in. If it’s the same, i would pass in null but if they don’t match, then I’ll pass the wasm in.
An additional thing to note is I intend to pass the gzipped wasm as an argument. Would that the file that needs to be hashed for comparision or is it the bare wasm. I want to be able to get back the same hash that’s installed in the target canister
Thoughts on how I would achieve this?
Hi @saikatdas0790
We usually do something like sha256="$(shasum -a 256 ./internet_identity.wasm.gz | cut -d ' ' -f1)"
.
A running canister will have as a module hash the hash of the thing that was uploaded, i.e. if you deployed a bare .wasm
then it will be the hash of that .wasm
file, if you uploaded a .wasm.gz
file then it will be the hash of .wasm.gz
(and not the unpacked wasm).
So yeah, comparing hashes should work fine.
1 Like