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?
    }
}
1
  • 1
    unless you call it as an external
    – Majd TL
    Oct 29, 2021 at 12:54

1 Answer 1

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.

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.