2

I'm confused about how msg.sender changes through relaying function calls. I know that msg.sender sets to the caller(it should be me) address at first, but through the process, msg.sender can change to contract address. Like when one contract calls the function of the another contract, then the function of the another contract's msg.sender should be the first contract. Now, if like this,

contract example1 {
  function A() {
    print msg.sender; // just fake code to imagine it prints out the result
    example2.B();
  }
}

contract example2 {
  function B() {
    print msg.sender; 
    C();
  }
  function C() { print msg.sender; }
}

If I call function A(), then it will print my address, and followed by the process, B() will print contract example1's address. Then is C() will print contract example1's address or contract example2's address?

1 Answer 1

2

Then is C() will print contract example1's address or contract example2's address?

It will print example1's address. When this code :

function B() {
    print msg.sender; 
    C();   }

will be executed, VM will read it like this:

function B() {
        print msg.sender;
        print msg.sender; // code of C()
}

That's why, it will print example1's address.

2
  • Thanks a lot. Could I ask you one more thing related about this? But I should change the example though.
    – Jung Chun
    Dec 6, 2018 at 12:52
  • Asking another question will be good as per the community guidelines.
    – Aniket
    Dec 6, 2018 at 13:00

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.