A contract view function is a type of function in a blockchain smart contract that allows users to view or read the state of the contract without making any modifications. These functions are non-mutating, meaning they do not change any state on the blockchain and do not require any gas fees for execution. They are typically used to retrieve information from a contract, such as balances or stored data.
The view functions in contracts allow you to read the state of the smart contract, and we can create table functions to analyze them.
How to create
E.g. If we want to create table function for ERC20 balanceOf view function:
/**
* @notice Get the number of tokens held by the `account`
* @param account The address of the account to get the balance of
* @return The number of tokens held
*/
function balanceOf(address account) external view returns (uint) {
return balances[account];
}