I’m trying to retrieve the principal of an actor class from within the actor class. Below is the code that I wrote… and below that is the error that I’m getting when trying to compile this code:
I believe that you have to bind this during instantiation of that actor. Check out how this is done in WhoAmI example in motoko playground. MotokoPlayground link
shared (install) actor class WhoAmI(someone : Principal) =
this { // Bind the optional `this` argument (any name will do)
public func idQuick() : async Principal {
return Principal.fromActor(this);
};
}
This only works for actor WhoAmI, not actor class WhoAmI(). For actor class, you need to bind the whole class, e.g. actor class WhoAmI() = WhoAmI { ... }