I’d like to charge a read fee each time an account wants to look up something in my smart contract . How possible is this? If so, what mechanism is recommended.
Everybody can read local and global state of your contract.
There is no way you can prevent that.
What you could in theory do (but I would strongly recommend against) is the following: somewhat obfuscate the content of the local/global storage and change the structure regularly by updating your smart contract.
This way, other smart contracts cannot rely on reading directly your state and you can force them to read information by calling your smart contract (and using the scratch pad to communicate in TEAL
In that case, your smart contract can require payment before executing.
Thanks for the response. An alternative way i thought about was that applications ‘Subscribe’ to my smart contract by opting in, and instead of updating the global state for my contract, the local state for each contract is updated, that way they have access to the value, and at the same time an inner transcation charges them a small fee.
Is the above design feasible? Especially if there are tens or hundreds of opted in applications?
It depends how the values people want to read are computed.
If they can be computed on-the-fly, you can indeed force the call to the smart contract somehow (it’s a bit like the obfuscated version above).
But nothing prevents the other smart contracts to simulate your smart contract to compute the values: after all, all the values your smart contract are using are public on the chain.
Note that I’m not sure to see how you use inner transactions to charge for fees.
You can require payment by making your application call preceded by a payment transaction in the group.