# How do i convert AccountId to a Text

**URL:** https://forum.dfinity.org/t/how-do-i-convert-accountid-to-a-text/10562
**Category:** Developers
**Created:** [January 28, 2022, 11:49pm UTC](https://forum.dfinity.org/t/how-do-i-convert-accountid-to-a-text/10562 "2022-01-28T23:49:46Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Jesse](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/jesse/32/37836_2.png) [@Jesse](https://forum.dfinity.org/u/Jesse)
#### Post date: [January 28, 2022, 11:49pm UTC](https://forum.dfinity.org/t/how-do-i-convert-accountid-to-a-text/10562/1 "2022-01-28T23:49:46Z")

</div>

@anon74414410 i have a follow up question to this comment 👇🏾

> [@Integrating with the Internet Computer ledger](https://forum.dfinity.org/t/integrating-with-the-internet-computer-ledger/2542/38):
>
> I’m learning this now! It’s a little non-trivial, although it is covered in the examples Roman provided. You can get an account-identifier by hashing the principal of the canister together with a “subaccount” which can be pretty much any other value converted into a blob. Any account-identifier that starts with your canister’s principal can be controlled by your canister. You’ll need to convert it into a string, for people to send money to it, though. Because this isn’t very easy to drop into…

Do you know where i can find an example of converting an `accounting-identifier` To a `Text`? I’m trying to do so by calling `Text.DecodeUtf8(accountId)` where `accountId` Is a `Blob`, but I’m just getting `null ` returned.

---

<div class="post-metadata">

### Author: ![PaulLiu](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/paulliu/32/4701_2.png) [@PaulLiu](https://forum.dfinity.org/u/PaulLiu)
#### Post date: [January 29, 2022, 6:25am UTC](https://forum.dfinity.org/t/how-do-i-convert-accountid-to-a-text/10562/2 "2022-01-29T06:25:21Z")

</div>

It is all binary. You can convert them to hex, I have [an example here](https://github.com/ninegua/tipjar/blob/main/src/tipjar/Util.mo#L145).

---

<div class="post-metadata">

### Author: ![coin\_master](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/coin_master/32/15963_2.png) [@coin\_master](https://forum.dfinity.org/u/coin_master)
#### Post date: [January 29, 2022, 9:44am UTC](https://forum.dfinity.org/t/how-do-i-convert-accountid-to-a-text/10562/3 "2022-01-29T09:44:42Z")

</div>

For reference to others, here’s an example to do that in typescript

> <https://github.com/Toniq-Labs/stoic-wallet/blob/1db3ed63cfe4bad68ca7c0783ad37f6b32757cd8/src/ic/utils.js#L45>

---

<div class="post-metadata">

### Author: ![Jesse](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/jesse/32/37836_2.png) [@Jesse](https://forum.dfinity.org/u/Jesse)
#### Post date: [January 29, 2022, 10:39pm UTC](https://forum.dfinity.org/t/how-do-i-convert-accountid-to-a-text/10562/4 "2022-01-29T22:39:34Z")

</div>

These were helpful. Got the job done ✅

---

<div class="post-metadata">

### Author: ![icme](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/icme/32/4327_2.png) [@icme](https://forum.dfinity.org/u/icme)
#### Post date: [August 5, 2024, 11:44pm UTC](https://forum.dfinity.org/t/how-do-i-convert-accountid-to-a-text/10562/5 "2024-08-05T23:44:41Z")

</div>

@quint Wrote an [encoding](https://github.com/aviate-labs/encoding.mo) library that others might find useful if they want to do this on the Motoko side of things.

```auto
import Hex "mo:encoding/Hex";

module {
    // Represents an account identifier that was derived from a principal & optional subaccount.
    public type AccountIdentifier = Blob; // Size 32

    // Hex string of length 64.
    public func toText(accountId : AccountIdentifier) : Text {
        Hex.encode(Blob.toArray(accountId));
    };
}

```
