useScaffoldContractRead
Use this hook to read public variables and get data from read-only functions of your smart contract.
const { data: totalCounter } = useScaffoldContractRead({
contractName: "YourContract",
functionName: "getGreeting",
args: ["ARGUMENTS IF THE FUNCTION ACCEPTS ANY"],
});
This example retrieves the data returned by the getGreeting
function of the YourContract
smart contract.
Parameters
Along with contractName
and functionName
, if the function accepts any arguments, they can be passed in the args
array. You can also pass other arguments accepted by useContractRead wagmi hook.
Return Values
- The retrieved data is stored in the
data
property of the returned object. - You can refetch the data by calling the
refetch
function. - The extended object includes properties inherited from wagmi useContractRead. You can check the useContractRead return values documentation to check the types.