ERC20: transfer amount exceeds allowance even after approving allowance

Can someone help me with this? Even after approving allowance to admin with 10 tokens by accountAddress and also allowance is updated and accountAddress as enough balance(100 * 10 ** 18) then to the transaction reverts due to allowance exceeded reason! Actually, I had a different code pattern earlier I was facing the same issue so I felt it might be some mistake in that so I tried to implement it in an easier and straightforward way, then too I’m getting the same error!

// address accountAddress = 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266; - accounts[0]
// address admin = 0x8626f6940e2eb28930efb4cef49b2d1f2c9c1199; - accounts[accounts.length - 1]
function deposit(uint _amount) public {
    console.log(IERC20(token).balanceOf(artistAddress));
    console.log(IERC20(token).allowance(artistAddress, admin));
    console.log(_amount);
    IERC20(token).transferFrom(accountAddress, address(this), _amount);
    emit Deposit(_amount);
}

tests

await tokenContract.methods
      .increaseAllowance(accounts[accounts.length - 1], web3.utils.toWei('10'))
      .send({ from: accounts[0], gas: 300000 });

await implementationContract.methods
      .deposit(web3.utils.toWei("9"))
      .send({
        from: accounts[accounts.length - 1],
        gas: 400000,
      });

logs

  Contract call:       <UnrecognizedContract>
  Transaction:         0xbd2fc5d7ffdf8e9a996a2215ca7fbd40038cc26d79ee6ea58e98b44d41486475
  From:                0x8626f6940e2eb28930efb4cef49b2d1f2c9c1199
  To:                  0x5c687e9f5405a043bd51eeb8dd34bd3651202875
  Value:               0 ETH
  Gas used:            74241 of 400000
  Block #1410:         0xbf1964151244e1bad2cfbe344e8d27250e93db42af772a05bba1f7ed4ae32bb0

  console.log:
    100000000000000000000
    10000000000000000000
    9000000000000000000

  Error: VM Exception while processing transaction: reverted with reason string 'ERC20: transfer amount exceeds allowance'

@SaicharanPogul, is the address of the contract implementing the deposit function the same as the admin address (it is not clear from your code snippets)? If it is not, then you need to approve the address of the contract that implements this function otherwise you will most certainly get the error you are reporting here.

Note: it looks like the address of the contract implementing deposit is 0x5c687e9f5405a043bd51eeb8dd34bd3651202875 based on the error logs you posted.

Thank You @TtheBC01, transferFrom() is a bit confusing. Now I understand it, calling transferFrom() in the different contract the caller of that function is the contract itself. I was totally confused for 3 days, even after giving allowance to admin by the user the transferFrom() was reverting with exceeded allowance reason.

1 Like