Completed: ICDevs.org - Bounty #26 - ICRC-1 Motoko - up to $10k

ICRC-1 uses the following type for accounts:

type Subaccount = blob;
type Account = record { owner : principal; subaccount : opt Subaccount; };

So the default accounts is just:

let canister account = {
   owner = Principal.fromActor(this);
   subaccount = null;
};

Additional accounts can be created by using the subaccount. You theoretically have infinity subaccount.

If you wanted to create an account that was specific for one of your users you would do:

let canister account = {
   owner = Principal.fromActor(this);
   subaccount = Principal.toBlob(msg.sender);  //maybe add some magic and hash for more privacy: see: https://github.com/ORIGYN-SA/origyn_nft/blob/99b9460eab0f841eb621deee7863d926d30421ae/src/origyn_nft_reference/utils.mo#L162
};
2 Likes