useWeb3Contract() requires params

Iā€™m using the following sample code from the react-moralis GitHub docs:

const ShowUniswapObserveValues = () => {
  const { data, error, runContractFunction, isFetching, isLoading } =
    useWeb3Contract();
...
}

This triggers an error: argument params is missing for useWeb3Contract()

https://github.com/MoralisWeb3/react-moralis#useweb3contract

it looks like there is also this syntax there:

  const { data, error, runContractFunction, isFetching, isLoading } =
    useWeb3Contract({
      abi: usdcEthPoolAbi,
      contractAddress: usdcEthPoolAddress,
      functionName: "observe",
      params: {
        secondsAgos: [0, 10],
      },
    });

check the second example, Iā€™m trying to execute a function and provide the params later

const ShowUniswapObserveValues = () => {
  const { data, error, runContractFunction, isFetching, isLoading } =
    useWeb3Contract();

  const options = {
    abi: usdcEthPoolAbi,
    contractAddress: usdcEthPoolAddress,
    functionName: "observe",
    params: {
      secondsAgos: [0, 10],
    },
  };

  return (
    <div>
      {error && <ErrorMessage error={error} />}
      <button
        onClick={() => runContractFunction({ params: options })}
        disabled={isFetching}
      >
        Fetch data
      </button>
      {data && <pre>{JSON.stringify(data)}</pre>}
    </div>
  );
};
https://github.com/MoralisWeb3/react-moralis/blob/31231e25f8bb079f5d29d0842d1c3218e73267a8/src/hooks/core/useWeb3Contract/useWeb3Contract.ts

maybe you can try with some empty parameters

1 Like