2

So yeah, who is the msg.sender if a function calls another function within the same contract?

contract A {
    function doSomething() {
        do2();
        //msg.sender == the user
    }
function do2() {
    //is msg.sender the user, or address(this) = this contract?
}

}

smenir443
  • 125
  • 1
  • 10

1 Answers1

6

It's the same msg.sender in both cases, which is the user. The caller does not change when the context does not leave the contract.

I recommend you try the contract you wrote on Remix.

And you also take a look at this thread: Who is msg.sender in a nested call chain?.

Update: as Majd mentioned in the comments, if you call the function as external, with the .call function, the msg.sender would be the contract itself.

Paul Razvan Berg
  • 17,902
  • 6
  • 73
  • 143