Solidity – Using TranferFrom in Delegate Call with ERC20 Tokens

erc-20erc-20-approveremixsolidity

I have an ERC20 test contract, also I did multicall with delegatecall function instead of call.
I have a three accounts: account1, account2, and account3.
account1 can spend tokens from account2 (I did transaction here, and this is works)

Then I tried to send the same transaction with multicall contract, and I got an error: ERC20: insufficient allowance, here a callstack

So I see in both transactions allowance call, but in the second transaction I see allowance as 0. How to fix that? and why that happened?

Best Answer

Delegatecall requires target and source to have compatible storage layouts. You'll be executing the target's bytecode in the source contract's storage. If the Multicall contracts delegatecalls to the ERC20 it will not work as you are expecting

  1. they don't have compatible layouts,
  2. it will be modifying the Multicall storage and not the ERC20 storage.

Check the answer for the Difference between CALL, CALLCODE and DELEGATECALL to understand the details.

Related Topic