How do i convert AccountId to a Text

@kpeacock i have a follow up question to this comment :point_down:t5:

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.

1 Like

It is all binary. You can convert them to hex, I have an example here.

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

4 Likes

These were helpful. Got the job done :white_check_mark:

@quint Wrote an encoding library that others might find useful if they want to do this on the Motoko side of things.

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));
    };
}
1 Like