LIGO views
Defining On-Chain Views
On-chain views can be defined using the @view attribute. For more information see here.
Calling On-Chain Views
let call_view : string => 'arg => address => option <'ret>
The primitive Tezos.call_view will allow you to call another contract view and get its result by providing the view name; the contract address and the parameter of the view. If the address is nonexistent; the name does not match of of the contract
view or the parameter type do not match, Tezos.call_view will return None.
Defining Off-Chain Views
In addition to on-chain views, LIGO views can be compiled and used as off-chain views (e.g. to be placed in metadata).
To compile an expression as a off-chain view, we can use the LIGO sub-command compile expression, passing the --function-body flag. Moreover, the --init-file argument can be passed to
re-use expressions from a file.
For example, if we have the following off_chain file containing a contract C:
We can compile function v from contract C as an off-chain view as follows:
Input
Output
Notice that v is not a contract entry of C (no @entry) nor a on-chain view (no @view), it is just a function declared in the context of the contract, which can be used as an off-chain view.