I have three different contracts. One is a simple contract (ContractA), second is my token contract and the third one is ERC20 Token contract which is inherited in my token contract. So when I make a request from my frontend (reactjs) to my ContractA it sends that request to my Token contract which sends the request to ERC20 token contract in order to transfer token to an address.
The problem that I am facing is that while calling the functions the address of the user is changed to the contract that is calling the other contract. How can I make the contract to be constant throughout the execution. Which means that the address of the contract should be the user that originated the request from the frontend.
Note: I can not change my implementation in my token contract as it is already deployed.
MyContract.sol
function sellTokens(address _from) public {
require(myToken.balanceOf(_from) >= 1);
myToken.transfer(_deployerAddress, 1);
}
Here is my sellTokens function that will transfer one token to the owner of the token. This is called from myContract file.
The transfer function is implemented in ERC20 token implementation from OpenZeppllin. Now when I call the transfer function it gets the msg.sender as the contract which is myContract. And in return it is giving me error for amount exceeds balance since myContract does not hold any tokens. myToken is the one in which ERC20 token is inherited.