Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do Env variables like signer_account_id cause error: ProhibitedInView?

I'm getting a ProhibitedInView error for a simple view function that does the following

export function getInfo(): Info {
   const caller = context.sender
   return infos.getSome(caller)
}

and realised that it's because of the context.sender call.

My assumption/understanding is that as long as a tx doesn't change the state, they can be considered ViewFunctions.

I found a warning against this on the Potential Gotchas, but why do the following functions cause view functions to fail? What does "binding methods that are exposed from nearcore" mean?

  • signer_account_id
  • signer_account_pk
  • predecessor_account_id
like image 839
j00yn Avatar asked Oct 22 '25 23:10

j00yn


1 Answers

On the context of a view functions, there is no such thing as:

  • signer_account_id
  • signer_account_pk
  • predecessor_account_id

It is not required to sign any message to run a view function, and moreover it is not allowed. It is more like inspecting a contract anonymously, nothing should be paid for that, and the result is independent from the caller. Because of this there is no signer_account_id and signer_account_pk.

On the other hand, it is not possible to make a cross-contract call, if you are initiating this call in view mode. Because of this there is no predecessor_account_id available, since signer_account_id is not available, and it is impossible that this was called from another contract.

like image 51
Marcelo Fornet Avatar answered Oct 25 '25 00:10

Marcelo Fornet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!