I have an usecase of rewarding the user who is actually sending the transactions and paying the gas for the transaction. As we know msg.sender returns the address from which the call came but, when the contract is called from another contract, msg.sender returns the called contract address. But in this case i need address of the user who has actually sent the transaction.
mapping(address=>uint256) public txSender;
function test() public {
address _txSender = getTxSender();
txSender[_txSender]++;
}
function getTxSender() public view returns(address) {
return msg.sender;
}
getTxSender not always returns actual user who is signing the tx.
You can access the original sender in the tx.origin
global variable.
Mind that using this variable for authorization is considered as a vulnerability.
So if you need to use the original sender address for authorization, you should pass the msg.sender
from the first contract - through the chain of internal transactions - to the final contract receiving the information.