Everything was working fine until I decided to make the token an actor class instead of an actor: somehow when I use an actor class, my other canister complains that the subaccount shall be a [Nat8] instead of a blob. What would it have anything to do with switchting from an actor to an actor class ? This is puzzling me.
I recreated a simple example here: GitHub - sardariuss/icrc1_airdrop. As is the compilation fails. Switch from actor class to actor in token/main.mo (and uncomment the hardcoded args) and it builds.
I cloned your repo and it failed to build with the same error using a class.
Commenting out the class header, to make it an actor (with suitable definitions for the arguments as locals) produces the same error at line 100.
However, changing line 100 to add a conversion compiles with both variant:
Yeah I’m not so sure if I should just do the conversion into a [Nat8] everywhere in my code right away or wait first to find the root cause. It’s especially strange to do this change because the ICRC1 Subaccount type defined in Types.mo is a Blob, not a [Nat8].
Something I just saw is that in the .dfx/local/canisters/token, in token.did I have: type Subaccount = blob;
whereas in service.did there is : type Subaccount = vec nat8;
In Candid, ‘blob’ is just an abbreviation for ‘vec nat8’, so it shouldn’t make a difference.
The issue is that Motoko ‘Blob’ and ‘[Nat8]’, which are distinct types, with different representations, both map to Candid ‘vec nat8’ so a Motoko author has to choose which interpretation they want when they implement a Candid function using ‘vec nat’.
Although it’s been a while, I remember encountering a related issue with both the official Motoko implementation and Natlabs’ version as constructor args involving a subaccount (adding a subaccount to either the minting account or any of the original deposits) would cause it to trap while deploying. Could be the same source?
While [nat8] and blob are similar in candid, [nat8] takes more memory. I think @quint was working on some improvements to blob, but I don’t know the status.
Status is: postponed I have not had the time to do a read-through of compile.ml, and won’t have any time soon… I wish I’d have some more time to learn about the Motoko compiler.