Hi,
I am trying to generate a unique address (principal) for each user so I can display it in the front end and the user can send ckBTC token to this address.
I tried to search for solutions and couldn’t find any. The closest I got was with this code that I found in this thread:
public type Account = { owner : Principal; subaccount : ?Blob };
public shared (msg) func getDepositAddress() : async Text {
let acc : Account = {
owner = Principal.fromActor(this);
subaccount = ?Principal.toBlob(msg.caller);
};
return Account.toText(acc);
};
However, it is trapping when I call the function because of this assertion in the Account.mo module.
assert (subaccount.size() == 32);
Please, do you have a working example somewhere? I feel like this should be really straightforward but I spent a couple of hours on it and couldn’t find a solution for this use case.