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

**URL:** <https://forum.dfinity.org/t/completed-icdevs-org-bounty-26-icrc-1-motoko-up-to-10k/14868>\
**Category:** Bounties & RFPs\
**Tags:** Discussing\
**Created:** [August 14, 2022, 4:16pm UTC](https://forum.dfinity.org/t/completed-icdevs-org-bounty-26-icrc-1-motoko-up-to-10k/14868 "2022-08-14T16:16:12Z")\
**Posts on this page:** 20\
**Page:** 3

<div class="post-metadata">

**Author:** ![blabagastered](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/blabagastered/32/8592_2.png) [@blabagastered](https://forum.dfinity.org/u/blabagastered)\
**Post date:** [January 9, 2023, 11:33am UTC](https://forum.dfinity.org/t/completed-icdevs-org-bounty-26-icrc-1-motoko-up-to-10k/14868/44 "2023-01-09T11:33:28Z")

</div>

Thank you. I only added ` = this` to the actor class line, and I’m now getting back a valid Principal but not the right one (browser console):

```auto
1. owner: Principal

  1. _arr: Uint8Array(10) [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, buffer: ArrayBuffer(10), byteLength: 10, byteOffset: 0, length: 10, Symbol(Symbol.toStringTag): 'Uint8Array']
  2. _isPrincipal: true

```

How do I get “this” to embody the backend canister’s Principal?

` subaccount = Principal.toBlob(msg.sender);` is returning as expected.

> [@skilesare](#):
>
> \_\_initargs : Types.InitArgs

If it’s to do with this part, how do I integrate \_\_initargs to my project?

---

<div class="post-metadata">

**Author:** ![blabagastered](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/blabagastered/32/8592_2.png) [@blabagastered](https://forum.dfinity.org/u/blabagastered)\
**Post date:** [January 9, 2023, 3:48pm UTC](https://forum.dfinity.org/t/completed-icdevs-org-bounty-26-icrc-1-motoko-up-to-10k/14868/45 "2023-01-09T15:48:20Z")

</div>

False alarm, it seems.

`Principal.toText(Principal.fromActor(this));` decodes to `"rrkah-fqaaa-aaaaa-aaaaq-cai"` , which is indeed my backend canister id.`

`[0, 0, 0, 0, 0, 0, 0, 1, 1, 1]` It’s probably the correct [Nat8] representation of the principal. It’s probably just the principal of the first canister deployed to the replica.

---

<div class="post-metadata">

**Author:** ![blabagastered](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/blabagastered/32/8592_2.png) [@blabagastered](https://forum.dfinity.org/u/blabagastered)\
**Post date:** [January 9, 2023, 7:51pm UTC](https://forum.dfinity.org/t/completed-icdevs-org-bounty-26-icrc-1-motoko-up-to-10k/14868/46 "2023-01-09T19:51:26Z")

</div>

> <https://github.com/dfinity/ICRC-1/blob/main/ref/Account.mo#L22>

I’m using a canister’s principal, blob size 10, as owner, and the assertion is failing (line 22) because it requires a Principal of blob size 32.

Is this a bug? If not, what’s going on?

---

<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:** [January 9, 2023, 8:20pm UTC](https://forum.dfinity.org/t/completed-icdevs-org-bounty-26-icrc-1-motoko-up-to-10k/14868/47 "2023-01-09T20:20:08Z")

</div>

@roman-kashitsyn This looks like some legacy stuff from back when canisters couldn’t hold ICP.

Actually…now that I look at it, this may be an old implementation from back before the new textual encoding was being discussed.

I think the actual encoding is more like:

```auto
//note: does not consider crc check on the blob bytes
account_icrc1_text = Principal.toText(Principal.fromActor(this)) # ":" # Conversion.valueToText(#Bytes(#frozen(hash)));

```

Decoding should be pretty straight forward if you just split on “:” and use something like [GitHub - aviate-labs/encoding.mo: Encoding Package for Motoko](https://github.com/aviate-labs/encoding.mo) to decode the second part.

See [ICRC-1 Account Human Readable Format - #42 by lastmjs](https://forum.dfinity.org/t/icrc-1-account-human-readable-format/14682/42)  
and [Announcing "Token Standard" as topic of the first meeting of the Ledger & Tokenization Working Group - #53 by Maxfinity](https://forum.dfinity.org/t/announcing-token-standard-as-topic-of-the-first-meeting-of-the-ledger-tokenization-working-group/11925/53)

We do really need to tie down the final format. I think we’re very close and if you go with principal:bytesinhexwithtruncated0s I think you’ll be ok. If it is intercanister you can ignore the CRC check anyway as no one will be copy/pasting it.

---

<div class="post-metadata">

**Author:** ![blabagastered](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/blabagastered/32/8592_2.png) [@blabagastered](https://forum.dfinity.org/u/blabagastered)\
**Post date:** [January 9, 2023, 8:32pm UTC](https://forum.dfinity.org/t/completed-icdevs-org-bounty-26-icrc-1-motoko-up-to-10k/14868/48 "2023-01-09T20:32:44Z")

</div>

Do you mean the ICRC-1 standard is not finalised yet? The textual encoding at least?

I’ll tell you what I’m trying to do:

I need my backend canister to give each authenticated user a unique string for them to send ICRCs to, so that the user can do that from any wallet, and so that when ICRCs arrive there, the canister owns them and knows which user they belong to.

The approach I was taking is

```auto
let user_account : Account = {
      owner = Principal.fromActor(this);
      subaccount = ?Principal.toBlob(callerId);
    };

```

and then

`let text_user_account = Account.toText(user_account);`

That’s when I hit that line 22 error.

If I understand correctly I need a Motoko function to get that `Principal.toBlob(callerId)` into a subbacount form that is compatible with `Account.toText()` from [ICRC-1/Account.mo at main · dfinity/ICRC-1 · GitHub](https://github.com/dfinity/ICRC-1/blob/main/ref/Account.mo)

---

<div class="post-metadata">

**Author:** ![blabagastered](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/blabagastered/32/8592_2.png) [@blabagastered](https://forum.dfinity.org/u/blabagastered)\
**Post date:** [January 9, 2023, 8:47pm UTC](https://forum.dfinity.org/t/completed-icdevs-org-bounty-26-icrc-1-motoko-up-to-10k/14868/49 "2023-01-09T20:47:08Z")

</div>

> [@skilesare](#):
>
> ```auto
> account_icrc1_text = Principal.toText(Principal.fromActor(this)) # ":" # Conversion.valueToText(#Bytes(#frozen(hash)));
> 
> ```

Though this doesn’t seem to include any referece to the subaccount. What is a textual representation for the case where the subaccount is present, and I want that subaccount to uniquely represent a user’s principal, so that the text end result is unique to the user.

---

<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:** [January 9, 2023, 8:54pm UTC](https://forum.dfinity.org/t/completed-icdevs-org-bounty-26-icrc-1-motoko-up-to-10k/14868/50 "2023-01-09T20:54:03Z")

</div>

We’ll you’ve got the right idea. Check out [A Christmas Hack: Minimum viable approvals](https://forum.dfinity.org/t/a-christmas-hack-minimum-viable-approvals/17668). When we get this finalized the principal will be the canister and the sub-account will be the hash of something that you can use to uniquely assign that sub-account to one of your users(or in the example an approver/transferer pair).

I don’t think many wallets have ICRC-1 integrated yet, so your best way to do this to initiate the transaction from your dapp and have your back-end canister take {owner; subaccount;}. Your UI can take care of displaying to the user(show textual encoding if desired). Your dapp can call something like getApprovalAccount in the example to get the proper subaccount to use.

Basically: You shouldn’t really ever have to have an update call take a text string…let the wallet/dapp handle that for you.

---

<div class="post-metadata">

**Author:** ![blabagastered](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/blabagastered/32/8592_2.png) [@blabagastered](https://forum.dfinity.org/u/blabagastered)\
**Post date:** [January 9, 2023, 9:00pm UTC](https://forum.dfinity.org/t/completed-icdevs-org-bounty-26-icrc-1-motoko-up-to-10k/14868/51 "2023-01-09T21:00:44Z")

</div>

Yes, I’m definitely not using the string for the backend, but I want to give the user a single string where funds can be send from anywhere in the IC and everything will work out as expected.

What I tried just now, given the error due to blob size, is turning the user’s principal blob into an account identifier with this function here: [examples/Account.mo at 433dd4afc1b1bba2c190993eaee44db33a1a237b · dfinity/examples · GitHub](https://github.com/dfinity/examples/blob/433dd4afc1b1bba2c190993eaee44db33a1a237b/motoko/ledger-transfer/src/ledger_transfer/Account.mo#L27)

And then use that as the subaccount here:

```auto

let user_account : Account = {
      owner = Principal.fromActor(this);
      subaccount = ACCOUNT_IDENTIFIER;
    };

```

and passing

```auto
let user_account_provisory : Account = {
      owner = Principal.fromActor(this);
      subaccount = ?Principal.toBlob(callerId);
    };

```

to `accountIdentifier()`

where

`ACCOUNT_IDENTIFIER = accountIdentifier(user_account_provisory)`

Then I do get back a string that I think and hope is both unique and functional. If you see problems with this approach please let me know.

---

<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:** [January 9, 2023, 9:07pm UTC](https://forum.dfinity.org/t/completed-icdevs-org-bounty-26-icrc-1-motoko-up-to-10k/14868/52 "2023-01-09T21:07:50Z")

</div>

Well…I just think that that particular code you are using is wrong now. We actually have a meeting tomorrow to hopefully finalize the human-readable encoding: [Announcing "Token Standard" as topic of the first meeting of the Ledger & Tokenization Working Group - #83 by dieter.sommer](https://forum.dfinity.org/t/announcing-token-standard-as-topic-of-the-first-meeting-of-the-ledger-tokenization-working-group/11925/83)

---

<div class="post-metadata">

**Author:** ![blabagastered](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/blabagastered/32/8592_2.png) [@blabagastered](https://forum.dfinity.org/u/blabagastered)\
**Post date:** [January 9, 2023, 9:14pm UTC](https://forum.dfinity.org/t/completed-icdevs-org-bounty-26-icrc-1-motoko-up-to-10k/14868/53 "2023-01-09T21:14:10Z")

</div>

Alright. Yes, we need to get this done. Textual encoding is very important partly because it allows third parties to send tokens to an account id or controlled by apps they have not had direct contact with / have had no business in producing.

I may turn up tomorrow if time allows.

---

<div class="post-metadata">

**Author:** ![dieter.sommer](https://avatars.discourse-cdn.com/v4/letter/d/b487fb/32.png) [@dieter.sommer](https://forum.dfinity.org/u/dieter.sommer)\
**Post date:** [January 11, 2023, 4:07pm UTC](https://forum.dfinity.org/t/completed-icdevs-org-bounty-26-icrc-1-motoko-up-to-10k/14868/54 "2023-01-11T16:07:32Z")

</div>

> [@skilesare](#):
>
> We actually have a meeting tomorrow to hopefully finalize the human-readable encoding: [Announcing “Token Standard” as topic of the first meeting of the Ledger & Tokenization Working Group - #83 by dieter.sommer](https://forum.dfinity.org/t/announcing-token-standard-as-topic-of-the-first-meeting-of-the-ledger-tokenization-working-group/11925/83)

We did not get to this agenda item in yesterday’s meeting and will now discuss in the meeting of January 24th. New contributors are of course warmly welcomed! 🙂

---

<div class="post-metadata">

**Author:** ![blabagastered](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/blabagastered/32/8592_2.png) [@blabagastered](https://forum.dfinity.org/u/blabagastered)\
**Post date:** [January 13, 2023, 9:50pm UTC](https://forum.dfinity.org/t/completed-icdevs-org-bounty-26-icrc-1-motoko-up-to-10k/14868/55 "2023-01-13T21:50:26Z")

</div>

If anyone happens to have tips or advice regarding deploying this Motoko ICRC repo as a canister that’s not in the readme do share.

I’ll probably start tinkering tomorrow.

---

<div class="post-metadata">

**Author:** ![tomijaga](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/tomijaga/32/4389_2.png) [@tomijaga](https://forum.dfinity.org/u/tomijaga)\
**Post date:** [January 20, 2023, 3:22am UTC](https://forum.dfinity.org/t/completed-icdevs-org-bounty-26-icrc-1-motoko-up-to-10k/14868/56 "2023-01-20T03:22:24Z")

</div>

There was a recent issue on the GitHub page regarding the custom Result type used by the [ICRC-1 reference implementation](https://github.com/dfinity/ICRC-1/blob/main/ref/ICRC1.mo#L97) which capitalizes the first letter of the `#ok` and `#err` variants.

> <https://github.com/NatLabs/icrc1/issues/3>
>
> Great work! 
> 
> While doing some related work, I noticed that the "official" \[ex…ample repository\](https://github.com/dfinity/ICRC-1/blob/main/ref/ICRC1.mo#L97) declares its \`Result\` type the way the ICP/NNS ledger canister does:
> 
> \`public type Result\<T, E\> = { #Ok : T; #Err : E };\`
> 
> Which is also how another \[implementation\](https://github.com/eimolad/eimolad\_icrc-1/blob/main/src/ICRC-1\_bronze/main.mo#L113) by @eimolad does it:
> 
> \`public type TransferResult = {
> #Ok : Tokens;
> #Err : TransferError;
> };\`
> 
> I'm not sure why #Ok/#Err is used over the base library's #ok/#err, but this would cause conflicts with future callers if one or the other is not consistently used. Maybe @skilesare knows which should be?

I’m curious why the Token Standard uses this type instead of the one in the base library.

---

<div class="post-metadata">

**Author:** ![tomijaga](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/tomijaga/32/4389_2.png) [@tomijaga](https://forum.dfinity.org/u/tomijaga)\
**Post date:** [January 24, 2023, 6:12am UTC](https://forum.dfinity.org/t/completed-icdevs-org-bounty-26-icrc-1-motoko-up-to-10k/14868/57 "2023-01-24T06:12:49Z")

</div>

I’ve updated the icrc1 lib to use the `TransferResult` type from the standard ([@7af28bb](https://github.com/NatLabs/icrc1/commit/7af28bbfa7d41a20297ff6e349ee0374f9d1b576)) and published a release version to [github](https://github.com/NatLabs/icrc1/releases/tag/0.0.1) and [mops](https://mops.one/icrc1)

---

<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:** [January 24, 2023, 1:25pm UTC](https://forum.dfinity.org/t/completed-icdevs-org-bounty-26-icrc-1-motoko-up-to-10k/14868/58 "2023-01-24T13:25:14Z")

</div>

> [@tomijaga](#):
>
> github

I was looking last night and I thought that there was a rosetta implementation, but I didn’t see any http\_request in the Token.mo. Have you done this yet or is it just the function that exists and it is up to the user to build the http\_request pipeline? I may have been looking in the wrong place!

---

<div class="post-metadata">

**Author:** ![tomijaga](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/tomijaga/32/4389_2.png) [@tomijaga](https://forum.dfinity.org/u/tomijaga)\
**Post date:** [January 25, 2023, 8:55pm UTC](https://forum.dfinity.org/t/completed-icdevs-org-bounty-26-icrc-1-motoko-up-to-10k/14868/59 "2023-01-25T20:55:50Z")

</div>

Hey @skilesare, sorry about the confusion, but this library does not contain an implementation of the rosetta API. It only implements the `get_transactions()` function needed by the [ic-rosetta-server](https://github.com/dfinity/ic/tree/master/rs/rosetta-api).  
I was under the impression that exchanges/users could run the server, connect it to an ICRC-1 token and make requests through it using the rosetta API standard instead of interacting with the coin directly via HTTP requests.  
If this is the case, I don’t think it would be necessary to add the `http_request()` function in `Token.mo` or for token creators to implement it themselves.

---

<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:** [January 25, 2023, 9:32pm UTC](https://forum.dfinity.org/t/completed-icdevs-org-bounty-26-icrc-1-motoko-up-to-10k/14868/60 "2023-01-25T21:32:19Z")

</div>

> [@tomijaga](#):
>
> ry to add the `http_request()` function in `Token.mo` or for token creators to implement it themselves.

I think you are right. DFINITY indicated to me that they will likely rewrite the rosetta node to support ICRC-1 in the coming month. This makes it harder to use an ICRC-1 token to go to a CEX, but we will hopefully get there eventually.

---

<div class="post-metadata">

**Author:** ![ZenVoich](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/zenvoich/32/5969_2.png) [@ZenVoich](https://forum.dfinity.org/u/ZenVoich)\
**Post date:** [January 26, 2023, 12:08pm UTC](https://forum.dfinity.org/t/completed-icdevs-org-bounty-26-icrc-1-motoko-up-to-10k/14868/61 "2023-01-26T12:08:16Z")

</div>

Hi @tomijaga, I tried to use this library as an interface to interact with the SNS-1 container and found that the subaccount type is `Blob` unlike the SNS-1 canister, which has `[Nat8]` type. Also ICP ledger canister uses `[Nat8]` for subaccounts.

[ICP ledger candid](https://dashboard.internetcomputer.org/canister/ryjl3-tyaaa-aaaaa-aaaba-cai)  
[SNS-1 candid](https://dashboard.internetcomputer.org/canister/zfcdd-tqaaa-aaaaq-aaaga-cai)

---

<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:** [January 26, 2023, 12:13pm UTC](https://forum.dfinity.org/t/completed-icdevs-org-bounty-26-icrc-1-motoko-up-to-10k/14868/62 "2023-01-26T12:13:25Z")

</div>

Nat8 and Blob are aliases for each other in candid. They should be interchangeable.

---

<div class="post-metadata">

**Author:** ![ZenVoich](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/zenvoich/32/5969_2.png) [@ZenVoich](https://forum.dfinity.org/u/ZenVoich)\
**Post date:** [January 26, 2023, 12:31pm UTC](https://forum.dfinity.org/t/completed-icdevs-org-bounty-26-icrc-1-motoko-up-to-10k/14868/63 "2023-01-26T12:31:05Z")

</div>

The inconvenience starts when you want to use the same subaccount data types as for the ICP ledger

```auto
type error [M0096], expression of type
  {owner : Principal; subaccount : ?Subaccount}
cannot produce expected type
  {owner : Principal; subaccount : ?Subaccount__1}

```

[Previous page](https://forum.dfinity.org/t/completed-icdevs-org-bounty-26-icrc-1-motoko-up-to-10k/14868.md?page=2)

[Next page](https://forum.dfinity.org/t/completed-icdevs-org-bounty-26-icrc-1-motoko-up-to-10k/14868.md?page=4)
