Examples/motoko/ledger-transfer at master · dfinity/examples

Arry.append is depricated use Buffer.append instead
Blob.fromArray(Array.append(crc32Bytes, hashSum))
I’ve read the doc but couldn’t understand it’s only taking one argument
func append(b : Buffer)
Can someone give an example how to use Buffer.append here

One thing I do when I can’t find an example is to check the tests in motoko base

Hi thanks for the info i will look in tests from now,
from what i understood hashSum and crc32Bytes are of types [Nat8]
so initialised 2 buffers of type [Nat8] and appended them
since Blob doesn’t take buffers i thought i should convert buffer to array back
var bToArray = B.toArray<[Nat8]>(buffer);

but i'm getting type error [M0072], field toArray does not exist in type
  module {
    type Buffer<X> =
        add : X -> ();
        append : Buffer<X> -> ();
        clear : () -> ();
        clone : () -> Buffer<X>;
        get : Nat -> X;
        getOpt : Nat -> ?X;
        put : (Nat, X) -> ();
        removeLast : () -> ?X;
        size : () -> Nat;
        toArray : () -> [X];
        toVarArray : () -> [var X];
        vals : () -> {next : () -> ?X}
    Buffer : <X>Nat -> Buffer<X>

am i converting it wrong here is the full function

public func accountIdentifier(principal: Principal, subaccount: Subaccount) : AccountIdentifier {
    let hash = SHA224.Digest();
    let hashSum = hash.sum();
    let crc32Bytes = beBytes(CRC32.ofArray(hashSum));

    var buffer = B.Buffer<[Nat8]>();
    for (i in Iter.fromArray(hashSum)) {

    var buffer2 = B.Buffer<[Nat8]>();

    for (i in Iter.fromArray(crc32Bytes)) {

    var bToArray = B.toArray<[Nat8]>(buffer);

    // Blob.fromArray(Array.append(crc32Bytes, hashSum))


This is weird, it’s literally right there in the type.
I remember there was an issue around this method, I think we need someone from motoko team.

I thought I’m doing it wrong
is it the correct way of doing it?

var bToArray = B.toArray<[Nat8]>(buffer);

I think it’s probably this issue:

The solutions from that thread amount to upgrading motoko-base to 0.7.0

Assuming that’s the answer here as well, you can do that like this if using Vessel:

Or by upgrading dfx:

Hi I’ve tried setting up vessel but I’m still getting the error field toArray does not exist
here’s what i updated in package-set.dhall as mentioned above

let upstream = https://github.com/dfinity/vessel-package-set/releases/download/mo-0.6.21-20220215/package-set.dhall sha256:b46f30e811fe5085741be01e126629c2a55d4c3d6ebf49408fb3b4a98e37589b
let Package =
    { name : Text, version : Text, repo : Text, dependencies : List Text }

  -- This is where you can add your own packages to the package-set
  additions =
    [] : List Package

  {- This is where you can override existing packages in the package-set

     For example, if you wanted to use version `v2.0.0` of the foo library:
     let overrides = [
         { name = "base"
         , version = "moc-0.7.0"
         , repo = "https://github.com/dfinity/motoko-base"
         , dependencies = ["base"]
  overrides =
    [] : List Package

in  upstream # additions # overrides

and set packtool to “vessel sources” in dfx.json
is there anything i’m missing?

Thanks got it working

Can you share how you got it working so anyone who faces the same issue would know the answer?

I’ve used this vessel package set

1 Like