Lambda View implementation have recently changed due to a recent protocol update. Lambda Views now utilize the
run_view endpoint. For more information refer to this document
Lambda View is a way to retrieve data from a smart contract's storage without incurring fees via a contract's view method.
Recap: Views & Callbacks
As you develop applications on the blockchain, you'll soon realize you not only want to interact with Smart Contracts by updating information but also by reading back pieces of data.
Many Smart Contracts have what's known as
view methods, which allow you to
specify parameters around what data you'd like to retrieve. They also require
you to supply a callback contract whose storage will update as a result of
executing the view method.
Limitations to Views & Callbacks
One issue with using views and callbacks is that, just like any operation executed on Tezos, each read has a small fee attached to it. The amount is trivial for occasional reads, but it becomes a burden at higher volumes.
Another drawback is speed: since we're invoking a contract method, we have to wait for confirmation to retrieve the requested data. You may not find this acceptable if the application you're working on requires consistent, faster response times.
Fortunately with the recently implemented
run_view endpoint, users can now run views without needing to inject operations into the blockchain. This means that no fees will be incurred when running views using this endpoint.
We have integrated the lambda view feature into the
ContractAbstraction class. This integration allows retrieving data from a very similar view to call other entry points of a smart contract with Taquito.
Here's an example of using the Lambda View on a FA1.2 contract.
Taquito dynamically creates a
getTotalSupply view method that the developer can call as follows:
Parameters must not include the callback parameter
Then we call the
read() method. (Note that we have no longer need a lambda contract)