Blockchain & Cryptocurrency Glossary

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

  • search-icon Clear Definitions
  • search-icon Practical
  • search-icon Technical
  • search-icon Related Terms

Msg.sender

1 min read
Pronunciation
[mess-ayj sen-der]
Analogy
`msg.sender` is like the return address on an envelope—it tells you who sent the message.
Definition
A global Solidity variable that returns the address of the immediate caller of the current function.
Key Points Intro
`msg.sender` provides caller context through:
Key Points

Immediate caller: Could be EOA or contract.

Used for access control: e.g., `require(msg.sender == owner)`.

Immutable per call: Fixed for the transaction frame.

Different from `tx.origin`: Safer for authorization.

Example
``` function withdraw() external { require(msg.sender == owner, "Not owner"); payable(owner).transfer(address(this).balance); } ```
Technical Deep Dive
The EVM pushes the caller’s address onto the call frame. Solidity exposes it as `msg.sender`. In nested calls, `msg.sender` updates to the last contract in the call chain, preventing phishing from shared origin.
Security Warning
Avoid using `tx.origin` for auth checks; always use `msg.sender` to prevent phishing via intermediary contracts.
Caveat
`msg.sender` changes in internal calls; design auth logic accordingly.

Msg.sender - Related Articles

No related articles for this term.