1

msg.sender (address): the sender of the message (current call).

Considering a scenario where a user uses a smart contract and try to perform a transaction. For that particular user msg.sender is the address of that user.

Does this address ever change for that specific user?

On what basis address is given to the caller? How its generated?

1 Answer 1

2

The msg.sender is always the address of the entity who called the current contract. When a contract calls another contract the msg.sender changes. Let me give you some examples.

Assuming we have a EOA (Externally Owned Account) A and contracts B and C. When A calls B the msg.sender in B is A's public address. If contract B also calls contract C, msg.sender in contract C is B's (contract) address.

So the address of a user never changes (assuming he uses the same account) but the msg.sender changes in contracts based on which entity initiated the call to that contract.

There is also tx.origin which is always A in the aforementioned example (in every contract which is called in the transaction from A), but this should typically not be used.

2
  • "So the address of a user never changes (assuming he uses the same account) but the msg.sender changes in contracts based on which entity initiated the call to that contract." With that being said, if the user uses a different account from what he uses earlier to perform transaction then msg.sender will have a different address? Does this mean msg.sender is depended of what account user uses from his wallet?
    – NinjaMAN
    Commented Jul 28, 2020 at 7:33
  • Yes, one user account means one private key which results in one public key which results in one public address. Different account has a different private key and therefore different public address. Commented Jul 28, 2020 at 7:35

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.