Approve function not working

When connecting to my dapp, by clicking on my frontend button, I get my approve function (smart contract call) call, the transaction works fine the first time, but when trying to test it again with the same metamask account that is approving the smart contract call, I end up not getting any smart contract call permission on the metamask account, the button freezes up and never works again with that metamask account… please I am really in need of help…

because I don’t know if it security that is blocking the approve smart contract call the second time… please I really need you guys

you have to give more information, what do you do after the first approve works for example

After approving the permission for another account to spend my token on my behalf, the other wallet spent the exact amount I approved smoothly. Then I tried the same steps the second time and the button just freezed without send any smart contract… I tried it multiple times but still did not work… the error showing on my browser console is I could not load the source.

Please I really need help on this, please

I don’t know why this could happen, what source to load?


Please here’s the error message

Please a quick question, can you give approval for some other account to spend your tokens on your behalf multiple times using the same wallet account?

Yes, You can give approval multiple time to spend a token.
The error which you shared is not related to the error from smart contract.

thanks for replying, please here is the error message.Capture

can you share your contract address, chain, and function ABI?

0xdAC17F958D2ee523a2206206994597C13D831ec7, ERC20 mainnet, [

If the error is happening from the smart contract then only this require statement could cause that error.

require(!((_value != 0) && (allowed[msg.sender][_spender] != 0)));

Try checking the allowance of the addresses using the allowance function. This should not be equal to 0, to complete the approve function.

Please I’m new to it, please can you run me a sample code of what the line of code should look like, so I could try it out? Thank you for helping.

This is the code to check the allowance of addresses. You need to update the params with the correct addresses.

const options = {
    chain: 'eth',
  address: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
  function_name: "allowance",
  abi: [{"constant":true,"inputs":[{"name":"_owner","type":"address"},{"name":"_spender","type":"address"}],"name":"allowance","outputs":[{"name":"remaining","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"}],
  params: {
      _owner: "ownerAddressHere",
      _spender: "SpenderAddressHere"
const result = await Moralis.Web3API.native.runContractFunction(options);

Thank you so so much @johnversus, I’m on at now. Update you in a bit, thanks.

For the “ownerAddressHere”, please how can I change it from a specific address to any signed in users address?

Should I replace it with the abi inputs name _owner?

You can get the loggedin user address using Moralis.User.current().get('ethAddress')
Is that what you are looking for?

You don’t have to edit the ABI. Only addresses in params need to be updated.