Calling another canister's methods

You can also use a canister id to access a previously deployed canister:


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

Where canister2’s id from the previous example can be passed in, similar to:

$ dfx canister call canister1 main "ic:6EF4FCAD1FD36EB654" --type string

Note the type signature actor { getValue: () -> async Nat } can be a subtype of that exposed by canister2.