0

I think I do everything correctly but... I get the transfer amount exceeds allowance error..... yes I could just use transfer() and that's it, but... should the transferFrom() also work? I don't get why it doesn't work.....

const usdc = (await getContractAt('@openzeppelin/contracts/token/ERC20/IERC20.sol:IERC20', USDC_ADDRESS)) as unknown as IERC20;

await usdc.connect(user).approve(flashLoanReceiver.target, FEE_AMOUNT);

console.log(await usdc.allowance(user.address, flashLoanReceiver.target));
console.log(FEE_AMOUNT);

await usdc.transferFrom(user.address, flashLoanReceiver.target, FEE_AMOUNT);

the logs give the exact same amount enter image description here

Thanks

2 Answers 2

1

try this: await usdc.connect(user).transferFrom(user.address, flashLoanReceiver.target, FEE_AMOUNT);

When you use transferFrom, amount is then deducted from the caller’s allowance

2
  • Yes, this should work Sep 29, 2023 at 16:57
  • no, it doesn't work
    – Eugene1111
    Oct 1, 2023 at 6:40
1

The thing is that the approve() method allows a spender to transfer tokens from the account or a contract that allowed to any address, thus the code tells that the flashLoanReceiver contract can spend user's tokens and not the way around.. So for the given code to work the transferFrom must be called from the contract code, or await token.connect(user).transfer() should be used, which is more suitable in this case

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.