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
- 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 ofshared
(shared query
) functions.
- A
shared query
function can call:- any local function.
- it cannot call any
shared
orshared query
functions, norawait
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.