# Compilation breaks when switching from actor to actor class

**URL:** <https://forum.dfinity.org/t/compilation-breaks-when-switching-from-actor-to-actor-class/21077>\
**Category:** Motoko\
**Created:** [June 29, 2023, 7:34pm UTC](https://forum.dfinity.org/t/compilation-breaks-when-switching-from-actor-to-actor-class/21077 "2023-06-29T19:34:58Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![sardariuss](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/sardariuss/32/39258_2.png) [@sardariuss](https://forum.dfinity.org/u/sardariuss)\
**Post date:** [June 29, 2023, 7:34pm UTC](https://forum.dfinity.org/t/compilation-breaks-when-switching-from-actor-to-actor-class/21077/1 "2023-06-29T19:34:58Z")

</div>

I was playing around with the ICRC-1 in motoko: [GitHub - NatLabs/icrc1: A full implementation of the ICRC-1 fungible token standard](https://github.com/NatLabs/icrc1/) that I imported through mops.

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](https://github.com/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.

---

<div class="post-metadata">

**Author:** ![claudio](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/claudio/32/322_2.png) [@claudio](https://forum.dfinity.org/u/claudio)\
**Post date:** [June 30, 2023, 7:55am UTC](https://forum.dfinity.org/t/compilation-breaks-when-switching-from-actor-to-actor-class/21077/2 "2023-06-30T07:55:35Z")

</div>

Thanks for the report and repro! I’ll try to take a look later today. Do you know which version of dfx/moc you were using?

---

<div class="post-metadata">

**Author:** ![sardariuss](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/sardariuss/32/39258_2.png) [@sardariuss](https://forum.dfinity.org/u/sardariuss)\
**Post date:** [June 30, 2023, 12:41pm UTC](https://forum.dfinity.org/t/compilation-breaks-when-switching-from-actor-to-actor-class/21077/3 "2023-06-30T12:41:41Z")

</div>

Thank you for having a look.

I use dfx 0.14.1:

> The command ‘“/home/tanguy/.cache/dfinity/versions/0.14.1/moc” “/home/tanguy/airdrop\_test/src/airdrop/main.mo” “-o” “/home/tanguy/airdrop\_test/.dfx/local/canisters/airdrop/airdrop.wasm” “-c” “–debug” “–idl” “–stable-types” “–public-metadata” “candid:service” “–public-metadata” “candid:args” “–actor-idl” “/home/tanguy/airdrop\_test/.dfx/local/canisters/idl/” “–actor-alias” “airdrop” “bkyz2-fmaaa-aaaaa-qaaaq-cai” “–actor-alias” “token” “bd3sg-teaaa-aaaaa-qaaba-cai” “–package” “base” “.mops/base@0.8.8/src” “–package” “map” “.mops/map@8.1.0/src” “–package” “icrc1” “.mops/\_github/icrc1@main/src” “–package” “array” “.mops/\_github/array@v0.2.0/src” “–package” “StableTrieMap” “.mops/\_github/StableTrieMap@main/src” “–package” “StableBuffer” “.mops/\_github/StableBuffer@v0.2.0/src” “–package” “itertools” “.mops/\_github/itertools@main/src”’ failed with exit status ‘exit status: 1’.

---

<div class="post-metadata">

**Author:** ![claudio](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/claudio/32/322_2.png) [@claudio](https://forum.dfinity.org/u/claudio)\
**Post date:** [June 30, 2023, 3:54pm UTC](https://forum.dfinity.org/t/compilation-breaks-when-switching-from-actor-to-actor-class/21077/4 "2023-06-30T15:54:55Z")

</div>

Odd.

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:

```auto
        subaccount = ?Blob.toArray(toSubaccount(principal));

```

Note that a candid `[vec nat8]` can be imported as Motoko `[Nat8]` or `Blob` so maybe there is some confusion between these going on elsewhere.

---

<div class="post-metadata">

**Author:** ![sardariuss](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/sardariuss/32/39258_2.png) [@sardariuss](https://forum.dfinity.org/u/sardariuss)\
**Post date:** [June 30, 2023, 6:11pm UTC](https://forum.dfinity.org/t/compilation-breaks-when-switching-from-actor-to-actor-class/21077/5 "2023-06-30T18:11:33Z")

</div>

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;

---

<div class="post-metadata">

**Author:** ![claudio](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/claudio/32/322_2.png) [@claudio](https://forum.dfinity.org/u/claudio)\
**Post date:** [July 1, 2023, 5:16pm UTC](https://forum.dfinity.org/t/compilation-breaks-when-switching-from-actor-to-actor-class/21077/6 "2023-07-01T17:16:48Z")

</div>

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’.

It’s confusing.

---

<div class="post-metadata">

**Author:** ![icaten](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/icaten/32/9897_2.png) [@icaten](https://forum.dfinity.org/u/icaten)\
**Post date:** [July 1, 2023, 10:27pm UTC](https://forum.dfinity.org/t/compilation-breaks-when-switching-from-actor-to-actor-class/21077/7 "2023-07-01T22:27:41Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![skilesare](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/skilesare/32/5609_2.png) [@skilesare](https://forum.dfinity.org/u/skilesare)\
**Post date:** [July 2, 2023, 1:33am UTC](https://forum.dfinity.org/t/compilation-breaks-when-switching-from-actor-to-actor-class/21077/8 "2023-07-02T01:33:37Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![quint](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/quint/32/40449_2.png) [@quint](https://forum.dfinity.org/u/quint)\
**Post date:** [July 2, 2023, 12:34pm UTC](https://forum.dfinity.org/t/compilation-breaks-when-switching-from-actor-to-actor-class/21077/9 "2023-07-02T12:34:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![claudio](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/claudio/32/322_2.png) [@claudio](https://forum.dfinity.org/u/claudio)\
**Post date:** [July 3, 2023, 9:37am UTC](https://forum.dfinity.org/t/compilation-breaks-when-switching-from-actor-to-actor-class/21077/10 "2023-07-03T09:37:52Z")

</div>

Candid [nat8] and blob are not only similar but literally the same:

> <https://github.com/dfinity/candid/blob/master/spec/Candid.md#syntactic-shorthands>

`blob` is just a short-hand for `[nat8]`.

In Motoko, `Blob` and `[Nat8]` are distinct types, though you can convert between them.

---

<div class="post-metadata">

**Author:** ![ZackDS](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/zackds/32/40368_2.png) [@ZackDS](https://forum.dfinity.org/u/ZackDS)\
**Post date:** [July 3, 2023, 12:49pm UTC](https://forum.dfinity.org/t/compilation-breaks-when-switching-from-actor-to-actor-class/21077/11 "2023-07-03T12:49:36Z")

</div>

So the same but different

---

<div class="post-metadata">

**Author:** ![claudio](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/claudio/32/322_2.png) [@claudio](https://forum.dfinity.org/u/claudio)\
**Post date:** [July 3, 2023, 4:51pm UTC](https://forum.dfinity.org/t/compilation-breaks-when-switching-from-actor-to-actor-class/21077/12 "2023-07-03T16:51:23Z")

</div>

Blobs take 1/4 of the space and, by not containing references to Motoko objects, place less stress on the GC (in the current implementation).
