Get the Type of an actor createed by an actor class

I am trying to instantiate an canister from its id:

actor {
    public func main(canisterId: Text) : async Nat {
        let canister2 = actor(canisterId): **actor { getValue: () -> async Nat };**
        return await canister2.getValue();

However, in my case I have defined the actor using an actor class, so am not sure how to declare the type signature. Anyway to get the type signature of the actor from the actor class?

In my case the asterisked code should be changed.


A class declaration declares both a function (the constructor) and a type of the same name, so you can use name of the class directly as a type.

Have you declared a class something like:

actor class Service () { public func getValue() : async Nat {...} }

then you can replace your ** … ** by Service (or Lib.Service if defined in an imported library called Lib).

Your inline description should actually work fine (but perhaps needs some extra parenthesis).


Thanks Claudio, tried something similar and it worked.