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"],
});

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)unknown[]Array of arguments to pass to the function (if accepts any). Types are inferred from contract's function parameters
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.