I have a contract we will call A that uses the transfer function from an ERC20 contract we will call B through an interface. However, the transfer function will not work as expected because in the call from user -> A -> B the msg.sender is now the contract address of A and not the user's address anymore.
I can think of two immediate ways to solve this.
- Pass the original msg.sender (user's address) as a param to the transfer function
- Change msg.sender in contract B's transfer function to tx.origin
However both of these solutions modify the ERC20 token standard contract which I am not sure if that is good practice.
I can see how this could be a common issue devs run into. Should I implement one of the above solutions even though it changes the standard contract? If not, then how should I solve it?
msg.senderis correct but the updates to balances won't be saved to storage associated with the token contract. – MrYellow Jun 23 '18 at 21:43approve/transferFrompattern. Also several draft standards coming up for adding a callback to inform a contract of tokens being sent. ERC223, ERC677, ERC827 – MrYellow Jun 25 '18 at 21:59