useWeb3Transfer() How to input amount as params

Hello, I have a problem with function useWeb3Transfer().

How can i input amount as an dynamic param when i call function Confirm. I tried useState setAmount but not working.
function useWeb3Transfer just run before i setAmount.

How to input this amount from outsite in here:

amount: Moralis.Units.Token(amount, process.env.NEXT_PUBLIC_CONTRACT_ADDRESS_DECIMAL),

I have this code snippet below on what I want to achieve

const {fetch, error, isFetching} = useWeb3Transfer({
    amount: Moralis.Units.Token(amount, process.env.NEXT_PUBLIC_CONTRACT_ADDRESS_DECIMAL),
    receiver: receiver,
    type: 'erc20',
    contractAddress: process.env.NEXT_PUBLIC_CONTRACT_ADDRESS_ERC20,
  });

const Confirm = async (amount, gem, gem_origin) => {
    setAmount(amount);
    setIsFetchingButton(true);
    await Moralis.enableWeb3({
      provider: 'web3Auth',
      clientId: process.env.NEXT_PUBLIC_API_KEY_WEB3AUTH,
      chainId: process.env.NEXT_PUBLIC_MAIN_NET_CHAINID,
      rpcTarget: process.env.NEXT_PUBLIC_RPC_TARGET,
      appLogo: process.env.NEXT_PUBLIC_URL + '/logo.png',
    });

    fetch({
      onSuccess: (tx) =>
        tx.wait().then(() => {
          addTx(tx.hash, amount, gem, gem_origin);
          setIsFetchingButton(false);
        }),
      onError: (error) => {
        setIsFetchingButton(false);
        console.log('amount', amount);
        console.log(error);
        toast.error('Error 🤯', {
          position: toast.POSITION.BOTTOM_RIGHT,
          theme: 'dark',
        });
      },
    });
  };

Hi @vampiregrodon

Have you tried using fetch functions for calling the hook directly? I believe it might accept the same params as useWeb3Transfer hook

Hi johnversus,

Can you sample code for using fetch functions for calling the hook directly ?

Thanks

Hi, that your mean ?

fetch({
      params: {
        amount: Moralis.Units.Token(amount, process.env.NEXT_PUBLIC_CONTRACT_ADDRESS_DECIMAL),
        receiver: receiver,
        type: 'erc20',
        contractAddress: process.env.NEXT_PUBLIC_CONTRACT_ADDRESS_ERC20,
      },
      onSuccess: (tx) =>
        tx.wait().then(() => {
          addTx(tx.hash, amount, gem, gem_origin);
          setIsFetchingButton(false);
        }),
      onError: (error) => {
        setIsFetchingButton(false);
        console.log('amount', amount);
        console.log(error);
        toast.error('Error 🤯', {
          position: toast.POSITION.BOTTOM_RIGHT,
          theme: 'dark',
        });
      },
    });

yeah, That is how you can use it

Awesome, thank you very much John :slight_smile: