By converting between Blob and [Nat8], I could make the backend compile (dfx build backend), but it still fails when I try to build the frontend which depends on the backend.
I created a repository to show the error and added the full error messages to the README there.
Typically blob and [Nat8] kind of “just work” in motoko public shared endpoints. I noticed in your week that it is saying that ?subaccount isn’t [Nat8] which means you are missing an opt somewhere. If this is in typescript, perhaps you need an array around your UInt8array? Arrays of one element are used to simulate opt such that subaccount: is null and [[1,1,…2,2]] is an opt blob/ opt [nat8]
There have been some errors from trying to simplify the issue from the original project. I fixed the frontend code, and the missing opt.
However, I still get the same error. Calling dfx build backend succeeds, but dfx build frontend, which depends on the backend,shows an error inside the Motoko file wallet.mo
/workspaces/motoko-blob-nat8/src/backend/wallet.mo:83.35-83.42: type error [M0096], expression of type
{owner : Principal; subaccount : ?[Nat8]}
cannot produce expected type
{owner : Principal; subaccount : ?Subaccount}
How can this file be ok when building the backend, but not when building the frontend?
Here are some more things I tried
If I change to Blob, I get the same error for both dfx build backend and dfx build frontend.
/workspaces/motoko-blob-nat8/src/backend/wallet.mo:83.35-83.42: type error [M0096], expression of type
{owner : Principal; subaccount : ?Blob}
cannot produce expected type
{owner : Principal; subaccount : ?Subaccount}
Thank you for spending the time to look into this. I wonder if there is some difference in the environment or commands you used to build the project.
I tried again with the patch in Github Codespaces which provides a clean Debian installation. Still get the same error.
Here is another video with the patch applied, from creating the codespace until getting the error (Link is to 3:15 where the actual build command starts): https://youtu.be/-2ZvrNMOPyA?t=195
I will use the workaround by casting to another actor in my project for now to not be stuck.
I see. I get the same error by using dfx 0.20.1. But if you upgrade to dfx 0.20.2, everything works fine. Not sure what changed between the dfx versions. You may also need to run npm install to get the typescript.
I can confirm that it works as expected with dfx 0.20.2.
Didn’t know there was a newer version as https://internetcomputer.org/install.sh still downloads 0.20.1 by default.
Just for reference if someone else runs into this, here is the current version numbers: