Metamask Cant process approve function on erc20

Im building a dapp on MetaMask and the MetaMask browser pops up but just keeps on loading( showing the spinning icon ) and gets stuck that way and when i close it , the console logs that user rejected the transaction. Im stuck and im at my wits end on what to do.
Nb. heres the code

 const contractMethod = new ethers.Contract(
      //get user approve function
      await contractMethod.approve(approveaddress, amount);

Do you have any more information on this? It’s fairly easy to handle the error in case the user rejects the prompt, but are you saying that you are not rejecting the MetaMask prompt and you are still getting this error saying so?

Do you have any screenshots or video of the issue? Anything to provide some additional context?


Like Eric Said, its hard to guess the rest of your code.
Anyhow here is a simple idea you could try.

async function f_approve ( _contractAddress, _addressToApprove, _anAmount){
    provider = new ethers.providers.Web3Provider( window.ethereum );
    signer = provider.getSigner();
    const contract = new ethers.Contract( _contractAddress, [ 'function approve(address spender, uint256 amount) public virtual override returns (bool)' ], signer );
    return await contract.approve( _addressToApprove, _anAmount );

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.