Getting actor (class) from Principal

I currently get a principals from actor classes from the following code:

let a = await ActorClass.ActorClass();
let p : Principal = Principal.fromActor(a); // Get principal from actor

Later, using that principal i want to make a connection back to the actor class. What is the syntax for doing so in Motoko?

let a = ActorClass.ActorClass(p); ??????

let a = ActorClass.ActorClass.fromPrincipal(p); ?????

I think this will help:

4 Likes

Just to be sure, you should never be doing that, unless you received the principal id from outside your program. This approach ruins all type safety.

If a program creates an actor, and later needs to call it, then it should simply store the actor reference, not just its principal id.

4 Likes