Approve and Transfer with moralis react

Hi, I’m using https://github.com/MoralisWeb3/react-moralis#useweb3contract to make calls to smart contract methods.

In my case I’m using it to call an approve on a ERC20 token and when I receive onSuccess callback I call a transfer (pretty standard stuff)

The second call (transfer) most of the time returns an error (execution reverted: ERC20: transfer amount exceeds allowance) because the first call (approve) has not yet changed the data in the smart contract.

Am I doing something wrong?

How to solve this issue?

Thanks

did you try execute function? https://github.com/MoralisWeb3/react-moralis#useweb3executefunction

useWeb3ExecuteFunction and useWeb3Contract apparently do the same, from the docs:

You can use the useWeb3ExecuteFunction hook to execute on-chain functions. You need to provide the correct abi of the contract, the corresponding contractAddress , the functionName that you would like to execute, and any parameters (params ) thet you need to send with the function.

You can use the useWeb3Contract hook to execute on-chain functions. You need to provide the correct abi of the contract, the corresponding contractAddress, the functionName that you would like to execute, and any parameters (params) thet you need to send with the function.

can you explain the difference?
Thanks

my initial impression was that useWeb3Contract uses runContractFunction and useWeb3ExecuteFunction uses executeFunction, meaning that one of them works only with read only functions (runContractFunction works only with read only functions and it doesn’t need a web3 instance)

Actually I’m using useWeb3Contract to call an approve method for a ERC20 contract (which is a write function) and it works, so I don’t think this is the difference.