Calling hooks in real world component

it’s a moralis function…

that code doesn’t not work… call fetch and nothing happens…

useWeb3ExecuteFunction works if isWeb3Enabled is true, so you can add isWeb3Enabled to the dependencies of the hook and check if it’s true before calling the fetch. Also try log error from the hook to keep track of the execution status

I don’t think you all understand…

you are not using real world examples in your docs…

maybe it works if it’s just that one function on the page and nothing else…

it runs that function and returns the results…

when you have a bunch of other functions on the the same page… as MOST real world applications have… it doesn’t work…

it shouldn’t be this hard to mint an nft

(web3, enableWeb3, isWeb3Enabled} = useMoralis()
your web3 doesn’t expose utils, or .eth so runcontactnative web3 doesn’t work…

The docs provides basic examples required to get basic things done which can be built upon to get complex things done.
Since you’re using react too, react docs explained in similar way ( basic example that can be used to build complex works )

real world examples would be A LOT more helpful…
most devs aren’t going to have a page with one function on it

Real-world examples are showcased in the weekly project series.

Error: Provided address 5.676064741032766e+47 is invalid, the capitalization checksum test failed, or it’s an indirect IBAN address which can’t be converted.

What are you trying to do ?

just trying to mint an nft…
have tried it this way

  const [_mintForm, setMintForm] = useState(null)

  useEffect(()=>{
    console.log('fetching....')
    const mintnftea = async()=> {
  
    {data_, error_ fetch, isFetching}  await useWeb3ExecuteFunction({
        abi: _nftea,
        contractAddress: '0x636c5AC57F13DdAB170d4064F0A3EB3f2949B885',
        functionName: "mint",
        params: {
          secondsAgos: [_mintForm.amount,_mintForm.redeems,_mintForm.metadataurl_.charCodeAt(0),_mintForm.ipfs,_mintForm.payTo,_mintForm.splitwith,_mintForm.split,_mintForm.redeemfrequency],
        },
      });
    }
  
  
  }, [mintnftea])

form gets submitted… NFTea gets minted…

web3, and every other way from your docs…

    const JSONdata = JSON.stringify(dataMint_)
    const endpoint = '/api/mintnftea'
    const options = {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSONdata,
    }
    const response = await fetch(endpoint, options)
    const result = await response.json()

sent it to the back end for the evm to do it

export default async function handler(req, res) {

  const body = req.body

  const functionName = 'mint';

  const chain = EvmChain.GOERLI;
  const params = {quantity_:body.amount,redeems_:body.redeems,data_:body.metadataurl_.charCodeAt(0),ipfs_:body.ipfs,payto_:body.payTo,splitwith_:body.splitwith,splitpercent_:body.split,redeemfrequency_:body.redeemfrequency};
  const address = process.env.NFTEA;

  await Moralis.start({
      apiKey: process.env.MORALIS_API_KEY,
  });

  const response = await Moralis.EvmApi.utils.runContractFunction({
      functionName,
      params,
      address,
      chain,
  });
  console.log(response.result);


    res.status(200).json({
      data: response.result
    });
}

doesn’t work and .charCodeAt(0) doesn’t work for the hex converstion

this way

      const {data_, error_, fetch, isFetching_}  = useWeb3ExecuteFunction({
        abi: _nftea,
        contractAddress: '0x636c5AC57F13DdAB170d4064F0A3EB3f2949B885',
        functionName: "mint",
        params: {
          secondsAgos: [_mintForm.amount,_mintForm.redeems,_mintForm.metadataurl_.charCodeAt(0),_mintForm.ipfs,_mintForm.payTo,_mintForm.splitwith,_mintForm.split,_mintForm.redeemfrequency],
        },
      });

then call fetch after the images is uploaded and saved to ipfs

fetch({params:dataMint_})

nothing happens…

Regards the first part of the code here, you can get it fixed as Glad mentioned above that hooks should be at the top level.

  const { isWeb3Enabled, enableWeb3 } = useMoralis();
  const [_mintForm, setMintForm] = useState(null);
  const { fetch } = useWeb3ExecuteFunction();

  useEffect(() => {
    const mintnftea = async () => {
      if (!isWeb3Enabled) await enableWeb3();
      
      fetch({
        params: {
          abi: _nftea,
          contractAddress: "0x636c5AC57F13DdAB170d4064F0A3EB3f2949B885",
          functionName: "mint",
          params: {
            secondsAgos: [
              _mintForm.amount,
              _mintForm.redeems,
              _mintForm.metadataurl_.charCodeAt(0),
              _mintForm.ipfs,
              _mintForm.payTo,
              _mintForm.splitwith,
              _mintForm.split,
              _mintForm.redeemfrequency,
            ],
          },
        },
        onSuccess: (res) => console.log(res),
        onError: (err) => console.log(err),
      });
    };
    mintnftea();
  }, []);

You should fix the dependency hook depending on what and when you want it to fire
You can keep track of the process with the logs from onSuccess and onError

As mentioned in the docs, runContractFunction run a given function of a contract abi and retrieve readonly data.

almost got it going…

      const {data, error, fetch, isFetching_}  = useWeb3ExecuteFunction({
        abi: _nftea,
        contractAddress: "0x636c5AC57F13DdAB170d4064F0A3EB3f2949B885",
        functionName: "mint",
        params: {
          quantity_: _mintForm.amount,
          redeems_: _mintForm.redeems,
          data_: _mintForm.metadataurl_.charCodeAt(0),
          ipfs_:  _mintForm.ipfs,
          payto_: _mintForm.payTo,
          splitwith_: _mintForm.splitwith,
          splitpercent_:_mintForm.redeemfrequency,
          redeemfrequency_:_mintForm.split
        },
      });

invalid address or ENS name (argument=ā€œnameā€, value=0, code=INVALID_ARGUMENT, version=contracts/5.6.0)

is there a special way to set addresses in react?
with qoutes, without… doesn’t work

Check if the address passed is a valid contract address

You should set it with quotes

invalid address or ENS name (argument=ā€œnameā€, value=0, code=INVALID_ARGUMENT, version=contracts/5.6.0)

Try hardcoding the contratc address and see if it works

set it as
export const _contractTea = ā€œ0x636c5AC57F13DdAB170d4064F0A3EB3f2949B885ā€;

still getting invalid address or ENS name (argument=ā€œnameā€, value=0, code=INVALID_ARGUMENT,

Then you should import it properly where it’s required.