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
| Parameter | Type | Description |
|---|---|---|
| contractName | string | The name of the contract to read from. |
| functionName | string | The name of the function to call. |
| args | any[] | An array of arguments to pass to the function (if accepts any). |
You can also pass other arguments accepted by useContractRead wagmi hook.
Return Values
- The retrieved data is stored in the
dataproperty of the returned object. - You can refetch the data by calling the
refetchfunction. - The extended object includes properties inherited from wagmi useContractRead. You can check the useContractRead return values documentation to check the types.