Can't call an imported Actor's query functions

For Motoko, the rules can be summarized like this

  • A user/frontend can call:
    • a shared function (with consensus and state change),
    • a shared query function (without consensus or state change).
  • A class constructor can call:
    • any local function.
  • A shared function (or async expression) can call:
    • any local function, and
    • any shared function (with consensus and state change), and
    • any shared query function (with consensus but no state change),
    • and await the results of shared (shared query) functions.
  • A shared query function can call:
    • any local function.
    • it cannot call any shared or shared query functions, nor await their results.

These rules are enforced dynamically on the platform (causing runtime traps when violated) but are checked statically in Motoko, to prevent traps.

On the platform, there is ongoing work to allow shared query functions to call other shared query functions, but we probably won’t expose that in Motoko until the implementation is done and, ideally, free of strange restrictions.

16 Likes