1

Consider following two simple contracts.

contract Provider {
  uint public constant value = 42;                                                                                                               
  event Caller(address addr);                                                                                                                    

  function provide() external returns (uint) {                                                                                                   
    emit Caller(msg.sender);                                                                                                                     
    return value;
  } 
} 
contract Counter {
  uint public counter;
  address public provider;
    
  constructor(address addr) {
    counter = 0;
    provider = addr;
  }

  function newvalue() public {
    counter += Provider(provider).provide();
  }
}

Let's say Provider is deployed at 0x1 and Counter is deployed at 0x2. Now a user with address 0x3 calls newvalue.

The event emitted from provide contains 0x2 as msg.sender. (i.e. the address of Counter)

Is there any way in which the original sender (i.e. 0x3) can be seen as msg.sender in all internal transactions?

Note that this is not an ideal curiosity. Many protocols have hardcoded transfering of tokens to msg.sender instead of taking an additional to argument. This makes calling those functions form other smart contracts extremely unwieldy.

0

It seems that one can use DelegateCall as explained here:

https://docs.soliditylang.org/en/v0.8.4/introduction-to-smart-contracts.html#simple-smart-contract

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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