Suppose there are 2 smart contracts and one human:

  1. The human calls a function of Contract 1.
  2. During processing the human's call, Contract 1 transfers some ETH to Contract 2.
  3. Some of Contract 2's code gets executed because of receiving the ETH from Contract 1.

During (3) when Contract 2's code is executed who will msg.sender be?

My guess is that it will be Contract 1's address, but if someone can provide some reference that confirms this that would be much appreciated please 🙂.

This question relates to this one but I would like to confirm whether or not there is a difference in the resulting msg.sender between calling a function of Contract 2 and the transfer of ETH triggering Contract 2's code.

1 Answer 1


There is no difference based on how the contract call is triggered. The context is switched to Contract 2 from Contract 1, and therefore in Contract 2 the msg.sender is Contract 1.

Here's a similar question & answer, with link to the official documentation: https://stackoverflow.com/a/48572142/2318492

  • Thanks! I guess the key idea is that transfer (to a contract) triggers a "call" meaning that the context switches as you've said. While the linked official documentation doesn't explicitly make this clear it seems clear enough and the documentation in the link states "msg.sender (address): sender of the message (current call)" which is very relevant. So thanks - I've accepted your answer but if you happen to know any specific documentation that clearly states something to the effect that "There is no difference based on how the contract call is triggered." that would be helpful too.
    – Daniel
    Commented Apr 16, 2021 at 0:21
  • Well, since we're talking about a decentralized network, there is no official documentation. As a side note, a contract can be called without switching the context with stuff like delegatecall, but that's an advanced topic and such is rarely used Commented Apr 16, 2021 at 4:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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