Map and Buckets Example

Got it! Really appreciate all the detailed explanations :100:

Here’s the code snippet:

let raw_rand = (actor "aaaaa-aa" : actor { raw_rand : () -> async Blob }).raw_rand;

One question: what happens if the Principal refers to a user and not a canister? What kind of error will be thrown when this code tries to call raw_rand?

You mean if you make an inter-canister call (this is just one instance of that) to a principal that is not one of an existing canister?

It should behave the same as if you’d made a call to a principal that could be a canister id, but no such principal exists, so you’ll get a reject response.

(Note that raw_rand is just a public method on the management canister aaaaa-aa).

I guess the real question is: how can we check if a principal refers to a canister or a user (to avoid these kind of situations)?

This thread seems to suggest that we can’t.

But this code by @witter seems to suggest that we can.


My advise is to just don’t worry. There is no reason to treat a principal that could be the identifier for an existing canister, but actually isn’t (because that canister does not exist) different from identifiers that (given knowledge about the current IC implementation) can’t be identifiers of such canisters. At least not in backend code – maybe in human-facing UI forms, such checks are sensible. But once you are past that, focus on “exists vs. does not exist”, and don’t worry about the “why” of “does not exist”.

Is there more I can read about this topic?