Skip to main content

useScaffoldReadContract

Use this hook to read public variables and get data from read-only functions of your smart contract.

const { data: totalCounter } = useScaffoldReadContract({
contractName: "YourContract",
functionName: "userGreetingCounter",
args: ["0xd8da6bf26964af9d7eed9e03e53415d37aa96045"],
query: {
enabled: true,
},
});

This example retrieves the data returned by the userGreetingCounter function of the YourContract smart contract.

Configurationโ€‹

ParameterTypeDescription
contractNamestringName of the contract to read from.
functionNamestringName of the function to call.
args (optional)any[]Array of arguments to pass to the function (if accepts any).
query (optional)objectAn object containing query options. The enabled property determines whether the query is automatically run or not. Set this to false to disable the query from automatically running.
watch (optional)booleanWatches and refreshes data on new blocks. (default : true)

You can also pass other arguments accepted by useReadContract 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 useReadContract. You can check the useReadContract return values documentation to check the types.