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

ParameterTypeRequiredDescription
contractNamestringYesName of the contract to read from.
functionNamestringYesName of the function to call.
argsunknown[]NoArray of arguments to pass to the function (if accepts any). Types are inferred from contract's function parameters
enablebooleanNoFetch data on mount
watchbooleanNoIf set to true, the data will be refetched on each block mine (default: false).

Return Values

  • The retrieved data is stored in the data property.
  • The loading state is stored in the isLoading property.
  • The error property stores any errors during reads.
  • You can refetch the data by calling the refetch function.
  • You can also use readContract function to read data. by filling the object parameter with - abi, address, functionName, args

Below is the configuration for readContract function:

Configuration

ParameterTypeRequiredDescription
abiobject[]YesABI of the contract to read from.
addressstringYesAddress of contract to read from.
functionNamestringYesName of the function to call.
argsunknown[]NoArray of arguments to pass to the function (if accepts any). Types are inferred from contract's function parameters