Is it possible for a contract to offer a "Pay per View" on-chain view that will only respond if a certain amount of Mutez is sent with the call, or are on-chain view calls always free?
1 Answer
on-chain views
do not mutate any state (storage, balances, etc.).
But it is possible to have a subscription system, where you can have an on-chain view
that verifies if the caller has an active subscription at the current time.
Example:
You create a contract that contains a view A
and a big_map(caller: address => expiration_date: timestamp) called subscriptions
in the storage.
Then you also have an entrypoint subscribe
that adds a given address as a subscriber for a certain period depending on the AMOUNT
sent when calling the respective entrypoint.
Now, when the caller calls view A
, the view can check if that SENDER
is an active subscriber and FAILWITH
if it is not.
Or you could also use callback entrypoints
, which is an asynchronous approach.