Query function with msg.caller?

How come it is not possible to have a function like this:

public query shared(msg) lookUpMyAccount(): async () {
accountsTable.get(msg.caller)
}

I figured since it’s still a read-only action, an actor should be able to call a query function passing in the msg.caller information. I get unexpected token “shared”.

Can one get the msg.caller for a query function?

Try:

public shared query(msg) func lookUpMyAccount(): async () {
  accountsTable.get(msg.caller)
}

(See production <shared_pat_opt> in the grammar at Motoko grammar :: Internet Computer)

(You’ve got shared after query and were missing the func keyword.)

10 Likes