How to get the principal of a canister in an Actor?

I want to get the principal of an actor, but


can only be used in actor class but not actor.
How can I solve this problem?


I think you can do as following, at least it is what I do:

import Principal "mo:base/Principal";

actor Manager {

  private func helloWorld(): async {
     let self: Principal = Principal.fromActor(Manager);

what if you want to check in a shared function from this manager actor that it got called by the actor principal. Then you need to call Principal.fromActor(Manager) every single call. Isn’t that affecting performance? Isn’t there a better way of doing this?

In my case, I pass down to the methods the variable - i.e. I call Principal.fromActor(Manager) only once in my actor. That way performance wise it is ok.

1 Like