[SOLVED] useWeb3ExecuteFunction retrieving variable

how can I retrieve a value from the smart contract using useWeb3ExecuteFunction() ?

in ethers it would be

   const nftNumber = await contract.totalNftStaked();
setSomething(nftNumber.toString() )

however I don’t succeed to retrieve a value from the smart contract and store it into a useState using
useWeb3ExecuteFunction
this is my code

  const contractProcessor = useWeb3ExecuteFunction();

 async function getUserNftIds() {
    let options = {
      contractAddress: "0x21daB594d4726d1e12fAD9b5aE7EE270C07F6b75",
      functionName: "getUserNftIds",
      abi: abi,
      params: {
        user: account,
      },
      // msgValue: val,
    };

    await contractProcessor.fetch({
      params: options,
      onSuccess: () => {
        console.log("Approval Received");
      },
      onError: (error) => {
        console.log("error", error);
      },
    });
  }

thank you

maybe this helps:

do you have a code where I can based on ?

try to put in a variable the result from await contractProcessor.fetch({

  async function getUserNftIds() {
    let options = {
      contractAddress: "0x21daB594d4726d1e12fAD9b5aE7EE270C07F6b75",
      functionName: "getUserNftIds",
      abi: abi,
      params: {
        user: account,
      },
      // msgValue: val,
    };

    const res = await contractProcessor.fetch({
      params: options,
      onSuccess: () => {
        console.log("Approval Received");
      },
      onError: (error) => {
        console.log("error", error);
      },
    });
    console.log(res);
    setStaked(res);
  }

image

what line generated that error?

thank you I made it work
the issue was the abi, its writing when I am inserting the abi function instead of all the abi.

1 Like