tx.origin
A Solidity global variable that returns the address of the externally owned account (EOA) that originally initiated the transaction.
tx.origin is a global variable in Solidity that returns the address of the account that originally initiated the current transaction. Unlike msg.sender, which returns the immediate caller, tx.origin traces back through the entire call chain to the very first sender.
tx.origin vs msg.sender
1// Call chain: EOA -> ContractA -> ContractB23// Inside ContractB:4// tx.origin == EOA (original transaction initiator)5// msg.sender == ContractA (immediate caller)
| Property | tx.origin | msg.sender |
|---|---|---|
| Returns | Original transaction sender | Immediate caller |
| Can be a contract | No (always EOA) | Yes |
| Changes through call chain | No | Yes (each call updates it) |
| Safe for authorization | No | Yes |
Why tx.origin Is Dangerous for Authorization
Using tx.origin in require statements for access control creates a phishing vulnerability:
1// VULNERABLE — do not use for authorization2function withdraw() external {3 require(tx.origin == owner, "Not owner");4 payable(msg.sender).transfer(address(this).balance);5}
An attacker can deploy a malicious contract and trick the owner into calling it. Since tx.origin still points to the owner, the authorization check passes and funds are drained.
1// SECURE — use msg.sender instead2function withdraw() external {3 require(msg.sender == owner, "Not owner");4 payable(msg.sender).transfer(address(this).balance);5}
Valid Use Cases
tx.origin has limited legitimate uses:
- Address blocking: Preventing a specific EOA from interacting with a contract, even through intermediary contracts
- Ensuring human interaction: Verifying the caller is an EOA (not a contract), though
msg.sender == tx.originis a fragile check that breaks with account abstraction
Best Practice
Always use msg.sender for authorization. The Solidity documentation and security community strongly recommend against using tx.origin for access control.
Articles Using This Term
Learn more about tx.origin in these articles:
Related Terms
msg.sender
A Solidity global variable that returns the address of the account or contract that directly called the current function.
EOA (Externally Owned Account)
A blockchain account controlled by a private key held by a person or entity, as opposed to a contract account controlled by code.
Phishing Attack
A social engineering technique where attackers trick victims into performing unintended actions, such as signing malicious transactions or calling harmful smart contract functions.
Access Control
Security mechanisms that restrict which addresses can call specific functions in a smart contract, preventing unauthorized actions.
Need expert guidance on tx.origin?
Our team at Zealynx has deep expertise in blockchain security and DeFi protocols. Whether you need an audit or consultation, we're here to help.
Get a Quote

