Calling CANISTER_ID env variable in motoko

Are these CANISTER_ID env variables reachable directly in motoko? That would come extremly handy for inter-canister call, especially for setup with segregated env (we have dev/test/prod deployment on IC)… :slight_smile:

1 Like

No, they aren’t at the moment, but you should be able to discover the principal and text of the principal using the names of the actors and functions Principal.fromActor and Principal.toText.

For example:

// Subscriber

import Publisher "canister:pub";
import Principal "mo:base/Principal";

actor Subscriber {

  public query func getPrincipal() : async (Principal, Principal, Text, Text) {
    let p1 : Principal = Principal.fromActor(Subscriber); // my principal
    let p2 : Principal = Principal.fromActor(Publisher); // imported Subscriber's principal
    let t1 : Text = Principal.toText(p1);
    let t2 : Text = Principal.toText(p2);
    (p1, p2, t1, t2);


If that’s not a solution, I’d be curious to know what else is missing.